Skip to content

Instantly share code, notes, and snippets.

@wordyallen
Last active March 30, 2016 02:38
Show Gist options
  • Save wordyallen/557bfdf44226fd68c6bc1456ce499575 to your computer and use it in GitHub Desktop.
Save wordyallen/557bfdf44226fd68c6bc1456ce499575 to your computer and use it in GitHub Desktop.
import React from 'react'
import {render} from 'react-dom'
import {createStore} from 'redux'
const reducer = (state = 0, action) => {
switch(action.type){
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
const App = ({value, onIncrement, onDecrement}) => (
<div>
<h1>{value}</h1>
<button onClick={onIncrement}>+</button>
<button onClick={onDecrement}>-</button>
</div>
)
const store = createStore(reducer)
render(<App
onIncrement={()=> store.dispatch({type: 'INCREMENT'})}
onDecrement={()=>store.dispatch({type: 'DECREMENT'})}
value={store.getState()}/>, document.getElementById('root'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment