Error handling via ErrorBoundary causing infinite loops #6160
-
Hello! i am using useQuery to load some data. The API may return 404 if the data does not exist. The component has an ErrorBoundary wrapped around it. I am letting ErrorBoundary handle the error. ErrorBoundary code is like this, where I want to render the error as well as the rest of the component.
The issue that I am running into is when the children renders, it calls the API again to get a 404, that eventually gets into an infinite loop. I wonder if I should be using the error property from useQuery to handle errors inside the component and only let ErrorBoundary handle mutation errors? Any advice / best practice is much appreciated, Thank you! :-) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
error boundaries usually don't render children - they render an error instead of the children, until the user confirms the error (e.g. with a button), at which point they re-mount the children to try rendering again. Imagine if there's a runtime error in |
Beta Was this translation helpful? Give feedback.
error boundaries usually don't render children - they render an error instead of the children, until the user confirms the error (e.g. with a button), at which point they re-mount the children to try rendering again.
Imagine if there's a runtime error in
children
. If the boundary catches it and then renders children again, it would also fail again, thus looping infinitely....