Read the React docs and cast the problem aside for a simple case, but still can't figure out what I'm doing wrong.
JSFiddle: https://jsfiddle.net/justin_levinson/pyn7fLq5/ or written below:
var TestForm = React.createClass({ render : function() { return ( <div> <p>Test Form</p> <form> <TestBox /> </form> </div> ) } }); var TestBox = React.createClass({ render : function() { return (<input type="checkbox" name={"testbox"} defaultChecked={true} onChange={this.handleCheck()}/>) }, handleCheck : function(event) { console.log("check"); console.log(event); } });
When the page loads, I get a “check” in the journal, followed by “undefined” for the event, after which it does not fire on subsequent clicks. Try this with both onClick and onChange, and also create a managed (checked = {true}) instead of an uncontrolled (defaultChecked = {true}) above.
Thanks!
source share