Guest User

Untitled

a guest
Jul 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. const defaultState = {
  2. authenticated: false
  3. };
  4.  
  5. const authReducer = (state = defaultState, action) => { //state is set to the default object using ES6 syntax. It's accepting the state, and the action.
  6. // change code below this line
  7. switch (action.type) { //switches on the values of the action that the reducer is accepting. Changes the state based on the result.
  8. case 'LOGIN':
  9. return {authenticated:true};
  10. break;
  11. case 'LOGOUT':
  12. return {authenticated:false};
  13. break;
  14. default:
  15. return state;
  16. break;
  17. }
  18. // change code above this line
  19. };
  20.  
  21. const store = Redux.createStore(authReducer); //passing the reducer into the createStore is telling the store what function is used to update the state.
  22.  
  23. const loginUser = () => {
  24. return {
  25. type: 'LOGIN'
  26. }
  27. };
  28.  
  29. const logoutUser = () => {
  30. return {
  31. type: 'LOGOUT'
  32. }
  33. };
Add Comment
Please, Sign In to add comment