Skip to content

docs: fix incorrect infinite loop claim in set-state-in-render#8413

Open
justismailmemon wants to merge 1 commit intoreactjs:mainfrom
justismailmemon:fix/docs-setstate-render
Open

docs: fix incorrect infinite loop claim in set-state-in-render#8413
justismailmemon wants to merge 1 commit intoreactjs:mainfrom
justismailmemon:fix/docs-setstate-render

Conversation

@justismailmemon
Copy link
Copy Markdown

@justismailmemon justismailmemon commented Apr 17, 2026

Summary

This updates the explanation in the set-state-in-render lint documentation.

Problem

The current documentation states that exceeding max will trigger an infinite loop:

"As soon as count exceeds max, an infinite loop is triggered."

However, in this specific example, the component stabilizes after an extra render because the condition becomes false once count is set to max.

Fix

This PR updates the wording to clarify that:

  • the issue is calling setState during render
  • this is an anti-pattern because rendering should remain pure
  • state updates should instead happen in an event handler or effect

Notes

The example code is unchanged, as it still correctly demonstrates the anti-pattern.

Closes #8411

@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