Skip to content

Instantly share code, notes, and snippets.

@vladinator1000
Last active March 5, 2018 19:50
Show Gist options
  • Save vladinator1000/f9db683a5b1fcec4f43cf5ec2b7744db to your computer and use it in GitHub Desktop.
Save vladinator1000/f9db683a5b1fcec4f43cf5ec2b7744db to your computer and use it in GitHub Desktop.
How to bind only once.
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