Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Created January 5, 2017 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanCCollins/f4d3c8cf00057f16468a74689152380d to your computer and use it in GitHub Desktop.
Save RyanCCollins/f4d3c8cf00057f16468a74689152380d to your computer and use it in GitHub Desktop.
Reducer example
export const initialState = {
error: null,
message: null,
isSubmitting: false,
modal: {
isVisible: false,
},
};
const feedbackReducer =
(state = initialState, action) => {
switch (action.type) {
case types.FEEDBACK_CLEAR_ALERTS:
return {
...state,
error: null,
message: null,
};
case types.FEEDBACK_SUBMISSION_INITIATION:
return {
...state,
isSubmitting: true,
};
case types.FEEDBACK_SUBMISSION_ERROR:
return {
...state,
isSubmitting: false,
error: action.error,
};
case types.FEEDBACK_SUBMISSION_MESSAGE:
return {
...state,
isSubmitting: false,
message: action.message,
};
case types.TOGGLE_FEEDBACK_MODAL:
return {
...state,
modal: {
isVisible: !state.modal.isVisible,
},
};
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment