T
TanStack4w ago
flat-fuchsia

Is it okay to use `CatchBoundary` component as a generic error boundary component?

Referring to https://tanstack.com/router/v1/docs/framework/react/api/router/catchBoundaryComponent I'll eventually be setting up Sentry to use their error boundary in most cases, but for cases where I'm handling known errors, I was wondering if CatchBoundary is safe to use as opposed to using something like react-error-boundary
CatchBoundary component | TanStack Router React Docs
The CatchBoundary component is a component that catches errors thrown by its children, renders an error component and optionally calls the onCatch callback. It also accepts a getResetKey function that...
4 Replies
passive-yellow
passive-yellow3w ago
can you clarify what you mean by "safe to use"?
flat-fuchsia
flat-fuchsiaOP5d ago
sorry - your reply got lost in my inbox 😅 by "safe" i mostly mean is it okay to use as a general purpose error boundary component, similar to what one might use react-error-boundary for?
passive-yellow
passive-yellow5d ago
no worries m8. looking at the source code it looks fairly similar to react-error-boundary. and it looks like it itself has nothing to do with routing, so I think it's good to use. (I use react-error-boundary myself but might switch to this, as I was unaware it existed.) one thing to note though is you'll also want to use this component above your router too in the off-chance that the router itself has an error and bubbles up and is uncaught
flat-fuchsia
flat-fuchsiaOP5d ago
nice - that's what i figured but i guess there are no promises that it couldn't change to be more router-specific at some point. will keep on using for now 👍

Did you find this page helpful?