Skip to content

Instantly share code, notes, and snippets.

@eva0919
Created January 2, 2016 07:05
Show Gist options
  • Save eva0919/4a8c3a76947b79e7627e to your computer and use it in GitHub Desktop.
Save eva0919/4a8c3a76947b79e7627e to your computer and use it in GitHub Desktop.
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
}) => (
<div>
<h1>{value}</h1>
<button onClick={onIncrement}>+</button>
<button onClick={onDecrement}>-</button>
</div>
);
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')
);
}
store.subscribe( render );
render();
@eva0919
Copy link
Author

eva0919 commented Jan 2, 2016

babel
redux

using in jsbin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment