Last active
January 3, 2019 12:50
-
-
Save treyhuffine/41908b173b585a6ec5a7472b83d62b97 to your computer and use it in GitHub Desktop.
A Redux reducer to manage a to-do list
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
// This will be fed into the reducer when the app loads to initialize the state | |
const getInitialState = () => ({ | |
todoList: [], | |
}); | |
const reducer = (prevState = getInitialState(), action) => { | |
switch (action.type) { | |
case 'ADD_TODO': | |
const nextState = { | |
todoList: [ | |
...prevState.todoList, | |
action.text, | |
], | |
}; | |
return nextState; | |
default: | |
return prevState; | |
}; | |
// console.log(store.getState()) => { todoList: [] } | |
// | |
// store.dispatch({ | |
// type: 'ADD_TODO', | |
// text: 'Get milk from the store', | |
// }); | |
// | |
// console.log(store.getState()) => { todoList: ['Get milk from the store'] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment