From 4dfb0fc0e68de5f3b2c615ba0cb59834b3755ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20Curley?= Date: Sat, 12 Oct 2024 08:36:24 +0100 Subject: [PATCH] types(react-query): export QueryErrorResetBoundaryFunction (#8089) * feat(react-query): export QueryErrorResetBoundaryFunction Export the QueryErrorResetBoundaryFunction render prop function signature so users don't have to write wierd types of there own * fix: add extra functions --------- Co-authored-by: Dominik Dorfmeister --- .../src/QueryErrorResetBoundary.tsx | 21 +++++++++++-------- packages/react-query/src/index.ts | 6 ++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/react-query/src/QueryErrorResetBoundary.tsx b/packages/react-query/src/QueryErrorResetBoundary.tsx index ba5fe3b2be..910215bcb6 100644 --- a/packages/react-query/src/QueryErrorResetBoundary.tsx +++ b/packages/react-query/src/QueryErrorResetBoundary.tsx @@ -2,11 +2,14 @@ import * as React from 'react' // CONTEXT +export type QueryErrorResetFunction = () => void +export type QueryErrorIsResetFunction = () => boolean +export type QueryErrorClearResetFunction = () => void export interface QueryErrorResetBoundaryValue { - clearReset: () => void - isReset: () => boolean - reset: () => void + clearReset: QueryErrorClearResetFunction + isReset: QueryErrorIsResetFunction + reset: QueryErrorResetFunction } function createValue(): QueryErrorResetBoundaryValue { @@ -33,10 +36,12 @@ export const useQueryErrorResetBoundary = () => // COMPONENT +export type QueryErrorResetBoundaryFunction = ( + value: QueryErrorResetBoundaryValue, +) => React.ReactNode + export interface QueryErrorResetBoundaryProps { - children: - | ((value: QueryErrorResetBoundaryValue) => React.ReactNode) - | React.ReactNode + children: QueryErrorResetBoundaryFunction | React.ReactNode } export const QueryErrorResetBoundary = ({ @@ -45,9 +50,7 @@ export const QueryErrorResetBoundary = ({ const [value] = React.useState(() => createValue()) return ( - {typeof children === 'function' - ? (children as Function)(value) - : children} + {typeof children === 'function' ? children(value) : children} ) } diff --git a/packages/react-query/src/index.ts b/packages/react-query/src/index.ts index ee14798ba8..5f372f4195 100644 --- a/packages/react-query/src/index.ts +++ b/packages/react-query/src/index.ts @@ -38,6 +38,12 @@ export type { QueryClientProviderProps } from './QueryClientProvider' export type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary' export { HydrationBoundary } from './HydrationBoundary' export type { HydrationBoundaryProps } from './HydrationBoundary' +export type { + QueryErrorClearResetFunction, + QueryErrorIsResetFunction, + QueryErrorResetBoundaryFunction, + QueryErrorResetFunction, +} from './QueryErrorResetBoundary' export { QueryErrorResetBoundary, useQueryErrorResetBoundary,