Skip to content

Instantly share code, notes, and snippets.

@mercykip
Last active July 19, 2021 13:25
Show Gist options
  • Select an option

  • Save mercykip/86e85b54a10c859da156d549cba51910 to your computer and use it in GitHub Desktop.

Select an option

Save mercykip/86e85b54a10c859da156d549cba51910 to your computer and use it in GitHub Desktop.
const initialState = {
/// users is an empty list of a list of users
users: [],
};
const userReducers = (state = initialState, action) => {
switch (action.type) {
case "ADD_USER":
return {
///the three dots are ES6 syntax(spread operator), it allows you to create copy of an abject
///make a copy of `state`
...state,
/// update the copy with the new value
user: action.payload
}
default:
// otherwise return the existing state unchanged
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment