Skip to content

Instantly share code, notes, and snippets.

@antondevv
Last active April 2, 2022 12:38
Show Gist options
  • Save antondevv/735380e4f139ee32532583c15eee0253 to your computer and use it in GitHub Desktop.
Save antondevv/735380e4f139ee32532583c15eee0253 to your computer and use it in GitHub Desktop.
reducer
const inititalState = { name: "User 1", age: 23 };
const addUserReducer = (state = inititalState, action) => {
switch (action.type) {
case "CHANGEUSERNAME": {
return { ...state, name: action.payload };
}
case "CHANGEAGE": {
return { ...state, age: action.payload };
}
}
return state;
};
export default addUserReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment