Skip to content

Conversation

@goran1010
Copy link
Contributor

@goran1010 goran1010 commented Jan 4, 2026

Because

This note from the lesson:

The unexpected infinite loop
The following is an infinite loop; can you guess why? Drop by in the TOP Discord server, tell us why, and score a brownie point!

function Component() {
   const [count, setCount] = useState(0);
 
   setCount(count + 1);
 
   return <h1>{count}</h1>;
 }

is rephrased to improve clarity.

This PR

  • Rephrase The following is an infinite loop; can you guess why? to The following would cause an infinite loop, but React can, under certain circumstances, detect infinite re-renders and throw an error. Can you guess why React will throw an error here, warning you about too many re-renders?

This makes it a bit clearer that the code in example would cause an infinite loop (but you wouldn't necessarily see it bricking your browser tab), if React didn't have the ability to sometimes detect it, and throw an error instead.

Issue

Closes #30622

Additional Information

I've decided to slightly change the wording (compared to my initial suggestion in the Issue itself) to better match the Error that React shows in the browser dev console:

Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@github-actions github-actions bot added the Content: React Involves the React course label Jan 4, 2026
Copy link
Contributor

@mao-sz mao-sz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@mao-sz mao-sz merged commit 30b94f6 into TheOdinProject:main Jan 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content: React Involves the React course

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More On State: Modify setCount example to improve clarity

2 participants