Last active
March 5, 2018 19:50
-
-
Save vladinator1000/f9db683a5b1fcec4f43cf5ec2b7744db to your computer and use it in GitHub Desktop.
How to bind only once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeForm extends React.Component { | |
constructor(props) { | |
super(props); | |
this.onSubmit = this.onSubmit.bind(this); | |
} | |
onSubmit() { | |
// ... | |
} | |
render() { | |
return( | |
<form onSubmit={this.onSubmit}> | |
Form Fields Here | |
</form> | |
); | |
} | |
} | |
// Or, if you don't want to .bind | |
class SomeForm extends React.Component { | |
onSubmit = () => { | |
// eyyy | |
} | |
render() { | |
return( | |
<form onSubmit={this.onSubmit}> | |
Form Fields Here | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment