Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

errorResetBoundary.ts

26 lines881 Bytes

1import { createContext, useContext } from 'octane'
2import type { QueryErrorResetBoundaryValue } from './types'
3​
4export function createValue(): QueryErrorResetBoundaryValue {
5 let isReset = false
6 return {
7 clearReset: () => {
8 isReset = false
9 },
10 reset: () => {
11 isReset = true
12 },
13 isReset: () => isReset,
14 }
16​
17// The reset coordinator for error-boundary retries. While "reset", a thrown query
18// error is NOT re-thrown (so the boundary's retry refetches instead of looping).
19// The default value means: without a `<QueryErrorResetBoundary>`, `isReset()` is
20// always false β€” identical to having no boundary.
21export const QueryErrorResetBoundaryContext =
22 createContext<QueryErrorResetBoundaryValue>(createValue())
23​
24export function useQueryErrorResetBoundary(): QueryErrorResetBoundaryValue {
25 return useContext(QueryErrorResetBoundaryContext)