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

useQueryErrorResetBoundary

更新于 2026-11-02 Preact 查看英文原文 ↗
TypeScript
1function useQueryErrorResetBoundary(): QueryErrorResetBoundaryValue;

定义位置:packages/preact-query/src/QueryErrorResetBoundary.tsx:92

该 Hook 将重置最近的 QueryErrorResetBoundary 内所有查询的错误。若未定义边界,则会在全局范围内重置这些错误。

返回值

QueryErrorResetBoundaryValue

该边界的 QueryErrorResetBoundaryValue。

示例

TypeScript
1import { useErrorBoundary } from 'preact/hooks'2import type { ComponentChildren } from 'preact'3import { useQueryErrorResetBoundary } from '@tanstack/preact-query'4 5function App({ children }: { children: ComponentChildren }) {6  const { reset } = useQueryErrorResetBoundary()7  const [error, resetError] = useErrorBoundary(() => reset())8 9  if (error) {10    return (11      <div>12        There was an error!13        <button onClick={() => resetError()}>Try again</button>14      </div>15    )16  }17 18  return children19}

本页为 TanStack Query 文档(Preact 版)的非官方中文翻译,原文由上游团队维护,遵循 MIT 许可。 译文如有偏差,以英文原文为准。

译自上游 59d11de