Open History to see the last commit
1import { useState, isChildrenBlock } from 'octane';
2import { QueryErrorResetBoundaryContext, createValue } from './errorResetBoundary.ts';
3import type { OctaneNode } from 'octane';
4β
5type QueryErrorResetBoundaryProps = {
6 children?: OctaneNode | ((value: ReturnType<typeof createValue>) => OctaneNode);
7};
8β
9// QueryErrorResetBoundary β provides a fresh reset coordinator to its subtree.
10// Place it above an error boundary; call `.reset()` from the boundary's retry so
11// the query refetches instead of immediately re-throwing. Children may be a
12// render prop receiving the boundary value β upstream's documented primary form:
13// `<QueryErrorResetBoundary>{({ reset }) => <ErrorBoundary onReset={reset}β¦/>}
14// </QueryErrorResetBoundary>` (react-query QueryErrorResetBoundary.tsx renders
15// `typeof children === 'function' ? children(value) : children`; octane
16// additionally excludes compiled children-blocks via isChildrenBlock).
17export function QueryErrorResetBoundary(props: QueryErrorResetBoundaryProps) @{
18 const [value] = useState(() => createValue());
19 const resolved =
20 typeof props.children === 'function' && !isChildrenBlock(props.children)
21 ? props.children(value)
22 : props.children;
23 <QueryErrorResetBoundaryContext.Provider
24 value={value}
25 >{resolved}</QueryErrorResetBoundaryContext.Provider>
26}