Skip to content

Instantly share code, notes, and snippets.

@chriscauley
Last active April 7, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriscauley/8405bd936f65569cefc826b5caf2a454 to your computer and use it in GitHub Desktop.
Save chriscauley/8405bd936f65569cefc826b5caf2a454 to your computer and use it in GitHub Desktop.
/* solution 1 */
onSubmit(data) {
Promise.resolve(this.props.submit(data)).then(
(result) => this.setState({ result: result })
)
}
/* solution 2 */
onSubmit(data) {
const result = this.props.submit(data)
if (prom instanceof Promise) {
result.then((promise_result) => {
this.setState({ result: promise_result })
})
} else {
this.setState({ result: result })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment