Skip to content
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

Refactor AI state update logic in Stock component #298

Closed
wants to merge 312 commits into from

Conversation

athrael-soju
Copy link

To address the warning from ESLint about missing dependencies in the useEffect and avoid the infinite loop issue when adding those dependencies, you can use a useCallback for the logic that updates the state, ensuring that it only changes when necessary. This approach helps in managing dependencies more effectively and prevents unnecessary re-renders or infinite loops.

The change introduces a useCallback that wraps the state update logic. The dependencies of useCallback include all the variables and functions it uses aiState, id, setAIState, startHighlight, endHighlight, xToDate, format. This ensures that updateAIState only changes when one of its dependencies changes, preventing unnecessary executions.

The useEffect hook then only needs to list startHighlight, endHighlight, and updateAIState as its dependencies. Since updateAIState is memoized and only changes when its dependencies change, it prevents the infinite loop issue while addressing the ESLint warning by correctly listing all dependencies.

Copy link

vercel bot commented Apr 2, 2024

@athrael-soju is attempting to deploy a commit to the Uncurated Tests Team on Vercel.

A member of the Team first needs to authorize it.

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.

None yet