Skip to content

Instantly share code, notes, and snippets.

@mushfiqweb
Created May 28, 2021 12:26
Show Gist options
  • Select an option

  • Save mushfiqweb/4d525129429e3fafc72ca4e67e32443b to your computer and use it in GitHub Desktop.

Select an option

Save mushfiqweb/4d525129429e3fafc72ca4e67e32443b to your computer and use it in GitHub Desktop.
{
users: [{ id: "1231", username: "Dale" }, { id: "1235", username: "Sarah"}]
}
{
type: "ADD_USER",
payload: { user: { id: "5123", username: "Kyle" } }
}
const userReducer = (state, action) => {
switch (action.type) {
case "ADD_USER":
return { ...state, users: [...state.users, action.payload.user ]}
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment