Skip to main content

QueryErrorResetBoundary

在查询中使用suspenseuseErrorBoundaries时,您需要一种方法让查询知道您想在发生错误后重新渲染时重试。使用该QueryErrorResetBoundary组件,您可以重置组件边界内的任何查询错误。

import { QueryErrorResetBoundary } from "@tanstack/react-query";
import { ErrorBoundary } from "react-error-boundary";

const App: React.FC = () => (
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary
onReset={reset}
fallbackRender={({ resetErrorBoundary }) => (
<div>
There was an error!
<Button onClick={() => resetErrorBoundary()}>Try again</Button>
</div>
)}
>
<Page />
</ErrorBoundary>
)}
</QueryErrorResetBoundary>
);

Options

  • QueriesObserver的选项与useQueries的完全相同。