Skip to content

Instantly share code, notes, and snippets.

@kilgarenone
Last active November 25, 2018 04:32
Show Gist options
  • Save kilgarenone/f119d512b82beb14d0321a6add74acb6 to your computer and use it in GitHub Desktop.
Save kilgarenone/f119d512b82beb14d0321a6add74acb6 to your computer and use it in GitHub Desktop.
render props exposes API
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