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

State Parameter: Current Snapshot

The first parameter represents the current state at the time the action is dispatched.

State Parameter: Current Snapshot

You'll learn what the first parameter in a reducer function represents and why it's called the "current" state.

What is the State Parameter?

Remember that a reducer has the signature (state, action) => newState. That first parameter — state — is the current snapshot of your state at the exact moment React calls your reducer.

Think of it like receiving a photograph in the mail. When you open the envelope, you're looking at how things were the moment the photo was taken. Similarly, when your reducer runs, the state parameter shows you exactly what your state looked like before this action was dispatched.

Why "Current" Matters

Every time you dispatch an action, React:

  1. Grabs the most recent state value
  2. Passes it as the first argument to your reducer
  3. Uses whatever your reducer returns as the new state
function reducer(state, action) {
  // 'state' here is the CURRENT snapshot
  // before this action is processed
  
  switch (action.type) {
    case 'INCREMENT':
      // state.count is what it was before this action
      return { ...state, count: state.count + 1 };
    default:
      return state;
  }
}

This is crucial because your reducer needs to know "where we are now" to compute "where we should be next." You're always calculating the next state based on the current state.

Not a Reference

The state parameter is a snapshot, not a live reference. You can't modify it directly — you must return a new object. This immutability is what allows React to detect changes and trigger re-renders.

Key Takeaway: The state parameter in your reducer is React's way of telling you "here's what your state looks like right now — use this snapshot to calculate what it should become."