Skip to content

Clarify reducer state updater convention#8536

Open
rickvian wants to merge 1 commit into
reactjs:mainfrom
rickvian:agent/use-prev-state-reducer
Open

Clarify reducer state updater convention#8536
rickvian wants to merge 1 commit into
reactjs:mainfrom
rickvian:agent/use-prev-state-reducer

Conversation

@rickvian

@rickvian rickvian commented Jul 16, 2026

Copy link
Copy Markdown

Summary

  • use prevState from setState argument instead of direct state value

Why

In Past, i actually have production design system component issue caused by someone updates state using existing state directly instead of using prevState from the parameter passed,
i do not want this approach creates bad habit.

The revised lesson teaches new readers the safe convention first: whenever new state is calculated from previous state, pass an updater function and call its argument prevState. It introduces batching only after the implementation is understood, as the reason the convention matters.

@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@rickvian rickvian marked this pull request as ready for review July 16, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant