Last active
March 30, 2016 02:38
-
-
Save wordyallen/557bfdf44226fd68c6bc1456ce499575 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 {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