-
-
Save rbiggs/02433d8f10f1b327b47f631603aa0d3e to your computer and use it in GitHub Desktop.
Handing the message to add a new item to the list component
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
| // actions gets two arguments: state and the message we send | |
| function actions(state, message) { | |
| switch(message) { | |
| case 'updateInputValue': | |
| // Update state with new value: | |
| state.inputValue = message.value | |
| // Don't forget to return state: | |
| return state | |
| case 'addItem': | |
| // Add new item to array: | |
| state.fruits.push({ | |
| key: state.newKey++, | |
| value: state.inputValue | |
| }) | |
| // Don't forget to return state: | |
| return state | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment