Skip to content

Graphite test#2 - #184

Open
Ubinquitous wants to merge 1 commit into
mainfrom
feature/test#2
Open

Graphite test#2#184
Ubinquitous wants to merge 1 commit into
mainfrom
feature/test#2

Conversation

@Ubinquitous

Copy link
Copy Markdown
Member

Issue Number

What

How

ScreenShot

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

Copy link
Copy Markdown

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
Copy Markdown
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