Skip to content

Instantly share code, notes, and snippets.

@jwill9999
Created June 26, 2017 19:46
Show Gist options
  • Save jwill9999/eb26d862492d440dbf7be03cc00dc078 to your computer and use it in GitHub Desktop.
Save jwill9999/eb26d862492d440dbf7be03cc00dc078 to your computer and use it in GitHub Desktop.
reducer example
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