Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created March 18, 2016 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/1a63b24d2cf6baf26498 to your computer and use it in GitHub Desktop.
Save ryanflorence/1a63b24d2cf6baf26498 to your computer and use it in GitHub Desktop.
saveAuthor(event) {
event.preventDefault();
if (!this.authorFormIsValid()) {
return;
}
if (this.state.author.id) {
this.props.actions.updateAuthor(this.state.author);
} else {
this.props.actions.createAuthor(this.state.author);
}
//Since setState doesn't immediately mutate this.state, need to set it separately here to assure
//it's updated for the check in routerWillLeave.
//More info: https://facebook.github.io/react/docs/component-api.html#setstate
this.setState({dirty: this.state.dirty}, () => {
alert('Author saved.');
this.context.router.push('/authors');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment