Created
March 18, 2016 16:20
-
-
Save ryanflorence/1a63b24d2cf6baf26498 to your computer and use it in GitHub Desktop.
This file contains 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
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