Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. const counter = (state = 0, action) => {
  2. if (action.type === 'INCREMENT') {
  3. return state + 1;
  4. } else if (action.type === 'DECREMENT') {
  5. return state - 1;
  6. } else {
  7. return state;
  8. }
  9. }
  10.  
  11.  
  12. const Counter = ({
  13. value,
  14. onIncrement,
  15. onDecrement
  16. }) => (
  17. <div>
  18. <h1>{value}</h1>
  19. <button onClick={onIncrement}>+</button>
  20. <button onClick={onDecrement}>-</button>
  21. </div>
  22. );
  23.  
  24. const { createStore } = Redux;
  25.  
  26. const store = Redux.createStore(counter);
  27.  
  28. const render = () => {
  29. ReactDOM.render(
  30. <Counter
  31. value={store.getState()}
  32. onIncrement={() =>
  33. store.dispatch({type: 'INCREMENT'})
  34. }
  35. onDecrement={() =>
  36. store.dispatch({type: 'DECREMENT'})
  37. }
  38. />,
  39. document.getElementById('root')
  40. );
  41. };
  42.  
  43. store.subscribe(render);
  44. render();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement