-
-
Save steevehook/370ad5636b308930ae02278a3fdf49d0 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
class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: 0, | |
}; | |
} | |
increment = () => { | |
this.setState(prevState => { | |
return { | |
count: prevState.count + 1, | |
}; | |
}); | |
}; | |
render() { | |
return ( | |
<div onClick={this.increment}>{this.props.children(this.state)}</div> | |
); | |
} | |
} | |
class App extends React.Component { | |
render() { | |
return ( | |
<Counter> | |
{state => ( | |
<div> | |
<h1>The count is: {state.count}</h1> | |
</div> | |
)} | |
</Counter> | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment