Skip to content

Instantly share code, notes, and snippets.

@nightspirit
Last active Apr 15, 2018
Embed
What would you like to do?
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