<Suspense/>, <ErrorBoundary/>, <ErrorBoundaryGroup/>, etc. are provided. Use them easily without any efforts.
It is simply extensions of react's concepts. Named friendly with originals like just <Suspense/>, <ErrorBoundary/>, <ErrorBoundaryGroup/>.
Suspensive provide clientOnly that make developer can adopt React Suspense gradually in Server-side rendering environment.
In this case, you can check isLoading and isError to handle loading and error states, and remove undefined from data in TypeScript.
If there are more APIs to query, the code to handle the loading state and error state becomes more complicated.
useSuspenseQuery can handle loading and error states externally using Suspense and ErrorBoundary.
However, since useSuspenseQuery is a hook, the component must be separated to place Suspense and ErrorBoundary in the parent, which causes the depth to increase.
Using SuspenseQuery, you can remove depth.
You remove the component called UserInfo, leaving only the presentational component like UserProfile, which makes it easier to test.
Or, there are times when you don’t want to use Suspense on the server.
Just wrap ClientOnly and it will be solved.
Easy, right?
Especially when working on a product like Admin, there are cases where designers do not specify each one, so you want to provide default values.
In that case, try using DefaultProps.
Then, how about using FadeIn?
The designer asked me to support Skeleton instead of the default Spinner in this part~! Just add it.
This has the issue of requiring resetKey to be passed down for deeply nested components. Additionally, you need to create a state to pass the resetKey.
Try using ErrorBoundaryGroup.
In such cases, try using the shouldCatch feature provided by Suspensive’s ErrorBoundary. By passing an Error Constructor to shouldCatch, you can handle only the specified errors.
In such cases, you can handle it by passing a callback to shouldCatch.