Skip to content

Instantly share code, notes, and snippets.

@aakashns
Last active December 5, 2017 05:04
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 aakashns/d08bf6c1dc16d06644a73f0691504ae3 to your computer and use it in GitHub Desktop.
Save aakashns/d08bf6c1dc16d06644a73f0691504ae3 to your computer and use it in GitHub Desktop.
A simple reducer to manage form state in Redux
const EDIT_CONTACT_FORM = "EDIT_CONTACT_FORM";
const CLEAR_CONTACT_FORM = "CLEAR_CONTACT_FORM";
const contactForm = (state = {}, action) => {
const { type, payload } = action;
switch (type) {
case EDIT_CONTACT_FORM:
return {
...state,
...payload
};
case CLEAR_CONTACT_FORM:
return {};
default:
return state;
}
};
export default contactForm;
export const editContactForm = edits => ({
type: EDIT_CONTACT_FORM,
payload: edits
});
export const clearContactForm = () => ({ type: CLEAR_CONTACT_FORM });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment