Actions are plain JavaScript objects that describe something that happened in the app. Every action must have a type field, a string such as 'ADD_TODO'. Any extra data usually goes in a payload field.
Dispatching an action is the only way to change Redux state, and the reducer reads its type to decide what to do. Because actions are plain objects, Redux DevTools can log and replay them.
An action creator, like addTodoAction below, is a function that builds the action object for you.
// Action object
const addTodo = {
type: 'ADD_TODO',
payload: {
id: 1,
text: 'Learn Redux'
}
};
// Action creator function
const addTodoAction = (text) => ({
type: 'ADD_TODO',
payload: { id: Date.now(), text }
});
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓