dark icon indicating copy to clipboard operation
dark copied to clipboard

Error boundaries and useQuery

Open einar-hjortdal opened this issue 5 months ago • 1 comments

This is a feature(s) request.

@dark-engine/core currently doesn't have error boundaries. Error boundaries are similar to Suspense: while Suspense "catches" promises, error boundaries catch errors. For this reason, in the React ecosystem these 2 are used together. An error boundary would simplify useQuery usage with the suspense-only strategy, given the following changes:

  • Suspend when isFetching
  • Throw error when error && (typeof data === 'undefined'). This error can be caught by an error boundary

This behavior guarantees data is defined when the component renders. Error handling and fallback can be moved outside of the component definition.

This feature request should be marked with low priority since useQuery {strategy: 'state-only'} is also available and would remain unchanged.

einar-hjortdal avatar Aug 28 '24 08:08 einar-hjortdal