Skip to content

Instantly share code, notes, and snippets.

@eldyvoon
Created December 17, 2019 10:01
Show Gist options
  • Save eldyvoon/497ed9e63879c6c8a724731946ea5920 to your computer and use it in GitHub Desktop.
Save eldyvoon/497ed9e63879c6c8a724731946ea5920 to your computer and use it in GitHub Desktop.
class Counter extends Component {
constructor(props) {
super(props);
this.state = { count: props.initCounter };
}
increase = () => this.setState(prevState => ({ count: prevState.count + 1 }));
decrease = () => this.setState(prevState => ({ count: prevState.count - 1 }));
render() {
const { count } = this.state;
return (
<div>
{this.props.children({
count,
increase: this.increase,
decrease: this.decrease
})}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment