Skip to content

Instantly share code, notes, and snippets.

@nightspirit
Last active April 15, 2018 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightspirit/d776e9dce9c894ddaf6d0b8ab9fa6c84 to your computer and use it in GitHub Desktop.
Save nightspirit/d776e9dce9c894ddaf6d0b8ab9fa6c84 to your computer and use it in GitHub Desktop.
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