Last active
July 19, 2021 13:25
-
-
Save mercykip/86e85b54a10c859da156d549cba51910 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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