Skip to content

[React 19]Calling setState inside useEffect causes 'Maximum update depth exceeded' #31978

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
TangJian-Eddie opened this issue Jan 5, 2025 · 2 comments
Labels

Comments

@TangJian-Eddie
Copy link

Summary

I noticed that while maximum update depth exceeded, Class Components will throw an Error, but Function Components only console.error only in the development environment. I’d like to understand the reason for this behavior and whether it’s possible for Function Components to also throw an Error. Our project aims to catch such errors promptly.

@mbilawalzaman
Copy link

To avoid the "Maximum update depth exceeded" error, ensure that you manage state updates properly inside useEffect, with the correct dependency array and conditions. If you want to enforce throwing an error instead of just logging it, you may need to use an error boundary or other custom error-handling mechanisms.

@henningsieh
Copy link

perhabs (?) this is related: TanStack/query#8677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants