useQueryErrorResetBoundary

· abundance's blog


This hook will reset any query errors within the closest QueryErrorResetBoundary. If there is no boundary defined it will reset them globally:

 1import { useQueryErrorResetBoundary } from '@tanstack/react-query'
 2import { ErrorBoundary } from 'react-error-boundary'
 3
 4const App = () => {
 5  const { reset } = useQueryErrorResetBoundary()
 6  return (
 7    <ErrorBoundary
 8      onReset={reset}
 9      fallbackRender={({ resetErrorBoundary }) => (
10        <div>
11          There was an error!
12          <Button onClick={() => resetErrorBoundary()}>Try again</Button>
13        </div>
14      )}
15    >
16      <Page />
17    </ErrorBoundary>
18  )
19}