Last active
June 8, 2017 05:18
-
-
Save TapaniAla/6c72d4e31226e96346b9e5c66ae496d3 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
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
const counter = (state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} | |
const Counter = ({ | |
value, | |
onIncrement, | |
onDecrement | |
}) => ( | |
<h1>{value}</h1> | |
<button onClick={onIncrement}>+</button> | |
<button onClick={onDecrement}>-</button> | |
); | |
const { createStore} = Redux; | |
const store = createStore(counter); | |
const render = () => { | |
ReactDOM.render( | |
<Counter | |
value={store.getState()} | |
onIncrement={() => | |
store.dispatch({ | |
type: 'INCREMENT' | |
}) | |
} | |
onDecrement={() => | |
store.dispatch({ | |
type: 'DECREMENT' | |
}) | |
} | |
/>, | |
document.getElementById('root') | |
); | |
} | |
// Needed to show initial state 0 | |
store.subscribe(render); | |
// Needed to show initial state 0 | |
render(); |
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
const counter = (state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} | |
const Counter = ({ value }) => ( | |
<h1>{value}</h1> | |
); | |
const { createStore} = Redux; | |
const store = createStore(counter); | |
const render = () => { | |
ReactDOM.render( | |
<Counter value={store.getState()}/>, | |
document.getElementById('root') | |
); | |
} | |
// Needed to show initial state 0 | |
store.subscribe(render); | |
// Needed to show initial state 0 | |
render(); | |
document.addEventListener('click', () => { | |
store.dispatch({type:'INCREMENT'}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment