Last active
April 15, 2018 05:41
-
-
Save nightspirit/d776e9dce9c894ddaf6d0b8ab9fa6c84 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
import React from 'react' | |
import { Provider } from './context' | |
class Counter extends React.Component { | |
constructor (props) { | |
super(props) | |
this.state = { | |
counter: { | |
value: 0, | |
inc: this.inc, | |
dec: this.dec | |
} | |
} | |
} | |
inc = () => { | |
this.setState(({counter})=>({ | |
counter: { | |
...counter, | |
value: counter.value+1 | |
} | |
})) | |
} | |
dec = () => { | |
this.setState(({counter})=>({ | |
counter: { | |
...counter, | |
value: counter.value-1 | |
} | |
})) | |
} | |
render () { | |
return ( | |
<Provider value={this.state.counter}> | |
<CounterCard/> | |
</Provider> | |
) | |
} | |
} | |
export default Counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment