Retry suspense queries
A suspense query throws into a React error boundary and the fallback offers a retry button.
TanStack · Class
QueryErrorResetBoundary scopes query-error resets to a component subtree. Give its render-prop reset function to an error boundary so a retry action can clear query errors before rendering again.
QueryErrorResetBoundary provides a reset function to descendant content. Pair that function with a React error boundary so a user-triggered reset clears query errors and allows queries using suspense or throwOnError to try again during a later render.
function QueryErrorResetBoundary(props: QueryErrorResetBoundaryProps): Element;| Name | Type | Description |
|---|---|---|
children | ReactNode | QueryErrorResetBoundaryFunction | Either rendered content or a function receiving QueryErrorResetBoundaryValue and returning rendered content. |
Element containing the supplied children.
import { QueryErrorResetBoundary } from '@tanstack/react-query'
import { ErrorBoundary } from 'react-error-boundary'
export function App() {
return (
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary
onReset={reset}
fallbackRender={({ resetErrorBoundary }) => (
<button onClick={resetErrorBoundary}>Try again</button>
)}
>
<Page />
</ErrorBoundary>
)}
</QueryErrorResetBoundary>
)
}Connects a React error boundary's reset action to TanStack Query's query-error reset function.
A suspense query throws into a React error boundary and the fallback offers a retry button.
Queries configured with throwOnError need coordinated recovery after an error fallback is reset.
Several related queries should share a reset lifecycle within one page or widget.
It is a React component that scopes query-error resetting to its boundary. Its children may be a render function receiving a reset value, which can be passed to an error boundary's onReset callback.
Follow-up: How does the hook differ? useQueryErrorResetBoundary resets errors in the closest component boundary, or globally when no boundary exists.
Use the component around the content whose query errors should be reset. Render-prop children receive reset, and the error boundary invokes that function when its fallback is reset.
Follow-up: Why connect onReset rather than only the fallback button? Because the error-boundary reset lifecycle is the event that should coordinate the query reset and the component re-render.
The component's children can be either a plain React node or a function receiving QueryErrorResetBoundaryValue. The rendered result is either returned directly or produced by calling that function.
Follow-up: What does the value currently expose? The documented example uses its reset function to clear query errors.
QueryErrorResetBoundaryPropsQueryErrorResetBoundaryFunctionQueryErrorResetBoundaryValueuseQueryErrorResetBoundarythrowOnError