框架
版本

useQueryErrorResetBoundary

此钩子将重置最近的 QueryErrorResetBoundary 内的任何查询错误。如果未定义边界,它将全局重置它们:

tsx
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
import { ErrorBoundary } from 'react-error-boundary'

const App = () => {
  const { reset } = useQueryErrorResetBoundary()
  return (
    <ErrorBoundary
      onReset={reset}
      fallbackRender={({ resetErrorBoundary }) => (
        <div>
          发生错误!
          <Button onClick={() => resetErrorBoundary()}>再试一次</Button>
        </div>
      )}
    >
      <Page />
    </ErrorBoundary>
  )
}
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
import { ErrorBoundary } from 'react-error-boundary'

const App = () => {
  const { reset } = useQueryErrorResetBoundary()
  return (
    <ErrorBoundary
      onReset={reset}
      fallbackRender={({ resetErrorBoundary }) => (
        <div>
          发生错误!
          <Button onClick={() => resetErrorBoundary()}>再试一次</Button>
        </div>
      )}
    >
      <Page />
    </ErrorBoundary>
  )
}