Skip to content

Instantly share code, notes, and snippets.

@rbiggs
Last active October 25, 2019 03:08
Show Gist options
  • Select an option

  • Save rbiggs/02433d8f10f1b327b47f631603aa0d3e to your computer and use it in GitHub Desktop.

Select an option

Save rbiggs/02433d8f10f1b327b47f631603aa0d3e to your computer and use it in GitHub Desktop.
Handing the message to add a new item to the list component
// 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