reactjs - Cannot read property 'setState' of undefined in React MailChimp Signup Form -


really new this, i've tried looking @ other examples not making sense, appreciated! trying have simple text field , submit button add email address mailchimp campaign list. simple (in theory) mailing signup list.

i keep getting error: typeerror: cannot read property 'setstate' of undefined onchange:

onchange(e) { 14 |    var email = e.target.value 15 |    this.setstate= this.setstate.bind(this); 16 |    this.setstate({email}) 17 | } 18 | render() { 

i've tried binding, doing right?

you don't need bind setstate function, onchange needs bind. , initializing state containing email es6 in constructor?

this.state = {      email : '' }  //bind onchange(e) ===== in constructor >  this.onchange = this.onchange.bind(this);  onchange(e) {     var email = e.target.value;     this.setstate({email} //or try this.setstate({email:email}); } 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -