Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Created December 3, 2017 15:53
Show Gist options
  • Save MicroBenz/a5e99e1e6c02cb95ac41dc6d23e5f753 to your computer and use it in GitHub Desktop.
Save MicroBenz/a5e99e1e6c02cb95ac41dc6d23e5f753 to your computer and use it in GitHub Desktop.
Recompose
import React, { Component } from 'react';
export default class Counter extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
this.handleCount = this.handleCount.bind(this);
}
handleCount(count) {
this.setState({ counter: this.state.counter + count });
}
render() {
const { counter } = this.state;
return (
<div>
Count: {counter}
<button onClick={() => this.handleCount(1)}>Increase</button>
<button onClick={() => this.handleCount(-1)}>Decrease</button>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment