Skip to content

Instantly share code, notes, and snippets.

@TapaniAla
Last active June 8, 2017 05:18
Show Gist options
  • Save TapaniAla/6c72d4e31226e96346b9e5c66ae496d3 to your computer and use it in GitHub Desktop.
Save TapaniAla/6c72d4e31226e96346b9e5c66ae496d3 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
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();
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