Skip to content

Instantly share code, notes, and snippets.

@steevehook
Forked from wwwhatley/Counter.jsx
Created July 16, 2018 06:37
Show Gist options
  • Save steevehook/370ad5636b308930ae02278a3fdf49d0 to your computer and use it in GitHub Desktop.
Save steevehook/370ad5636b308930ae02278a3fdf49d0 to your computer and use it in GitHub Desktop.
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