译零 TransZero · TanStack Query v4 中文文档
主站

useQueryErrorResetBoundary

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

TypeScript
1import { useQueryErrorResetBoundary } from '@tanstack/react-query'2import { ErrorBoundary } from 'react-error-boundary'3 4const App: React.FC = () => {5  const { reset } = useQueryErrorResetBoundary()6  return (7    <ErrorBoundary8      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}