Skip to content

Graphite test#2 #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Graphite test#2 #184

wants to merge 1 commit into from

Conversation

Ubinquitous
Copy link
Member

Issue Number

What

How

ScreenShot

Comment on lines +6 to +8
useEffect(() => {
setState((prev) => !prev);
}, [state]);
Copy link

Choose a reason for hiding this comment

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

The current implementation creates an infinite loop. The useEffect has state in its dependency array while also updating that same state variable inside the effect body. This creates a cycle where:

  1. The effect runs
  2. setState updates the state
  3. The state change triggers the effect to run again
  4. The cycle repeats indefinitely

To resolve this, either:

  • Remove state from the dependency array if the effect should only run once
  • Or modify the logic to avoid updating the state that's in the dependency array

This pattern can cause performance issues and potentially crash the application.

Suggested change
useEffect(() => {
setState((prev) => !prev);
}, [state]);
useEffect(() => {
setState((prev) => !prev);
}, []);

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about remove this hook? It is looks like no need IMO

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