Actions are the sole mechanism for communicating an intent to change state in Redux — a component dispatches an action object, and the store passes it, along with the current state, to the reducer, which decides how, if at all, the state should change in response. By convention, an action's type field is a string, often written in SCREAMING_SNAKE_CASE or namespaced like 'todos/add', describing what happened in past tense or as an event name, and any additional data the reducer needs is typically bundled under a payload field, an established convention rather than a strict requirement enforced by Redux itself.
1Understanding Actions
Actions are the sole mechanism for communicating an intent to change state in Redux — a component dispatches an action object, and the store passes it, along with the current state, to the reducer, which decides how, if at all, the state should change in response. By convention, an action's type field is a string, often written in SCREAMING_SNAKE_CASE or namespaced like 'todos/add', describing what happened in past tense or as an event name, and any additional data the reducer needs is typically bundled under a payload field, an established convention rather than a strict requirement enforced by Redux itself.
An action object should describe what happened, not how the state should change — the reducer, not the action, is responsible for deciding exactly how a given action actually transforms the state, keeping that decision logic centralized in one place rather than scattered across wherever actions happen to be dispatched.
const addTodoAction = {
type: 'todos/add',
payload: { text: 'Buy milk', done: false }
};
console.log(addTodoAction.type, addTodoAction.payload.text);2Practical Example
Here is a real-world application of Actions showing how it is used in production React code.
function addTodo(text) {
return {
type: 'todos/add',
payload: { text, done: false }
};
}
console.log(addTodo('Walk the dog'));3Best Practices
Follow these guidelines when working with Actions:
1. Give every action a clear, descriptive type field, conventionally namespaced like 'todos/add', describing what happened rather than how state should change
2. Bundle any additional data an action carries under a payload field, following Redux's common, though not strictly enforced, action-object convention
3. Keep actions themselves as plain, simple data, no functions or class instances, so they remain fully serializable, which is exactly what enables tools like Redux DevTools to record and replay them
Tip: An action object should describe what happened, not how the state should change — the reducer, not the action, is responsible for deciding exactly how a given action actually transforms the state, keeping that decision logic centralized in one place rather than scattered across wherever actions happen to be dispatched.
const addTodoAction = {
type: 'todos/add',
payload: { text: 'Buy milk', done: false }
};
console.log(addTodoAction.type, addTodoAction.payload.text);