Skip to content

Instantly share code, notes, and snippets.

@dariocravero
Created August 25, 2016 01:38
Show Gist options
  • Save dariocravero/02ac58f5154668cedd51b928382dda8c to your computer and use it in GitHub Desktop.
Save dariocravero/02ac58f5154668cedd51b928382dda8c to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
const click = () => ({
type: 'CLICK'
})
const reducer = (state={clicked: false}, action) => {
switch (action.type) {
case 'CLICK':
return {
clicked: true
}
default: return state
}
}
class Thing extends Component {
dispatch(action) {
this.setState(reducer(this.state, action))
}
render() {
return <div onClick={() => this.dispatch(click())} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment