Created
June 26, 2017 19:46
-
-
Save jwill9999/eb26d862492d440dbf7be03cc00dc078 to your computer and use it in GitHub Desktop.
reducer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AUTH_USER, UNAUTH_USER, AUTH_ERROR } from '../actions/types.js'; // types | |
export default function (state = {}, action) { | |
switch (action.type) { //set up switch | |
case AUTH_USER: | |
return { ...state, error: "", authenticated: true }; // return previous state as spread operator plus updated state | |
case UNAUTH_USER: | |
return { ...state, authenticated: false }; | |
case AUTH_ERROR: | |
return { ...state, error: action.payload }; | |
} | |
return state; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment