Last active
November 25, 2018 04:32
-
-
Save kilgarenone/f119d512b82beb14d0321a6add74acb6 to your computer and use it in GitHub Desktop.
render props exposes API
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 Hello extends React.Component { | |
state = { isSubmitting: false } | |
handleThisClick = () => { | |
/* do your thing here */ | |
} | |
handleFormSubmit = async event => { | |
event.preventDefault(); | |
this.setState({ isSubmitting: true }) | |
try { | |
const response = await fetch(/* stuffs */) | |
this.setState({ isSubmitting: false }) | |
} catch(err) { | |
console.log(err); | |
} | |
} | |
render() { | |
return ( | |
{this.props.children({ | |
handleFormSubmit: this.handleFormSubmit, | |
handleThisClick: this.handleThisClick, | |
isSubmitting: this.state.isSubmitting | |
})} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment