Trying to learn React JS / JSX at the moment and have gotten stuck creating a simple login form:
/**
* @jsx React.DOM
*/
var loginForm = React.createClass({
getInitialState: function() {
return {loggedIn : false};
},
login : function(event) {
alert('logging in');
},
logout : function(event) {
alert('logging out');
},
render: function() {
return (
<div>
<form /*action={this.server+'/login.php'}*/>
<label htmlFor="username">Username:</label>
<input type="text" id="username" name="username" />
<label htmlFor="password">Password:</label>
<input type="password" id="password" name="password" />
</form>
</div>
<div>
<button onClick={this.login}> Login </button>
<button onClick={this.logout}> Logout </button>
</div>
)
}
});
React.renderComponent(
<loginForm />,
document.body
);
If I remove the <button>
tags it works fine but otherwise an error is thrown:
Uncaught Error: Parse Error: Line 27: Unexpected identifier
<button onChange={this.logout}> Logout ...
^
fiddle: http://jsfiddle.net/4TpnG/90/