useQueryErrorResetBoundary
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}