Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import { createStore } from 'redux';
  2.  
  3. const increment = () => ({
  4. type: 'INCREMENT',
  5. });
  6.  
  7. const decrement = () => ({
  8. type: 'DECREMENT',
  9. });
  10.  
  11. function counter(state = 0, action) {
  12. switch (action.type) {
  13. case 'INCREMENT':
  14. return state + 1;
  15. case 'DECREMENT':
  16. return state - 1;
  17. default:
  18. return state;
  19. }
  20. }
  21.  
  22. const store = createStore(counter);
  23.  
  24. store.subscribe(() => console.log(store.getState()));
  25.  
  26. store.dispatch(increment());
  27. store.dispatch(decrement())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement