September 2018
Beginner
156 pages
3h 28m
English
Actions let you define the operations that the user can perform to update the state of the application. An Action is a JavaScript object of the { type, payload } shape, where type is a string mentioning the user action and payload is the data with which the state should be updated:
let todoId = 0;export const addTodo = text => ({ type: 'ADD_TODO' payload: { text, id: todoId++, isCompleted: false }})
Here, the addTodo action accepts a TODO text and indicates that the Action is used to add a TODO to a list of TODOs. payload here is an object containing the TODO text, a TODO ID, and a Boolean flag, isCompleted (set to false). It's also possible to have actions that don't require the payload property to be included. For example, consider ...
Read now
Unlock full access