Created
January 5, 2017 03:47
-
-
Save RyanCCollins/f4d3c8cf00057f16468a74689152380d 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
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