Skip to content

docs: correct inaccurate infinite loop claim in set-state-in-render#8412

Open
Assamee wants to merge 1 commit intoreactjs:mainfrom
Assamee:docs/issue-8411-set-state-in-render
Open

docs: correct inaccurate infinite loop claim in set-state-in-render#8412
Assamee wants to merge 1 commit intoreactjs:mainfrom
Assamee:docs/issue-8411-set-state-in-render

Conversation

@Assamee
Copy link
Copy Markdown

@Assamee Assamee commented Apr 17, 2026

Fixes #8411

Summary
The current documentation for the set-state-in-render lint rule states that a specific condition (e.g. count < max) will trigger an infinite loop. While this is an anti-pattern that causes unnecessary re-renders, the claim of an "infinite loop" is inaccurate in this specific code example.

In the provided snippet, the component stabilises once the state update condition becomes false. I have updated the wording to clarify that the core issue is the violation of render purity, rather than a guaranteed infinite loop.

Testing and Verification
I replicated the documentation's example in a local Vite/React environment to verify the actual behaviour:

  1. Scenario: Initialised count at 0 with a max of 5.
  2. Observation: The component performed exactly 6 renders.
  3. Result: Once count reached 5, the condition count < max evaluated to false, and the component successfully settled.
  4. Conclusion: This confirmed that while the code is an anti-pattern, it does not result in an infinite loop.

@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! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Mistake]: set-state-in-effect gives a wrong example of bad usage

1 participant