Course contentsShow
← React
Lesson 756 of 2,39620. useReducerFree lesson

Action Parameter: Instruction Object

The second parameter is an object describing what happened, typically with a 'type' property.

Action Parameter: Instruction Object

What you'll learn: How the second parameter to a reducer function—the action object—tells your reducer what change to make.

The Instruction Object

You've seen that a reducer is a function taking (state, action) => newState. The action is the second parameter, and it's typically a plain JavaScript object that describes what happened in your application.

Think of actions as instruction cards you hand to a chef. Each card doesn't just say "cook" — it specifies exactly what to cook: "make pasta" or "prepare salad." Similarly, actions tell your reducer what state change to perform.

The 'type' Property

By convention, action objects almost always include a type property:

// Common action object structure
const action = {
  type: 'INCREMENT'
};

The type is a string (often in uppercase) that identifies the kind of state transition you want. It's the label on your instruction card.

Actions Can Carry Additional Data

Beyond type, actions often include extra data needed to perform the update:

const action = {
  type: 'ADD_TODO',
  text: 'Learn reducers'
};

const anotherAction = {
  type: 'UPDATE_COUNT',
  amount: 5
};

This additional data is sometimes called the "payload," though you can name properties however makes sense for your app.

Why an Object?

Using an object (rather than just a string) gives you flexibility. You can pass all the information your reducer needs in a single, structured package. Your reducer will read action.type to decide what to do, then use the other properties to know how to do it.

Key Takeaway: The action parameter is an instruction object, typically with a type property identifying the operation, plus any additional data needed to perform that state update.