Last active
December 5, 2017 05:04
-
-
Save aakashns/d08bf6c1dc16d06644a73f0691504ae3 to your computer and use it in GitHub Desktop.
A simple reducer to manage form state in Redux
This file contains 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
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