Skip to content

Commit

Permalink
types(react-query): export QueryErrorResetBoundaryFunction (#8089)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
DogPawHat and TkDodo authored Oct 12, 2024
1 parent babf66f commit 4dfb0fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/react-query/src/QueryErrorResetBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = ({
Expand All @@ -45,9 +50,7 @@ export const QueryErrorResetBoundary = ({
const [value] = React.useState(() => createValue())
return (
<QueryErrorResetBoundaryContext.Provider value={value}>
{typeof children === 'function'
? (children as Function)(value)
: children}
{typeof children === 'function' ? children(value) : children}
</QueryErrorResetBoundaryContext.Provider>
)
}
6 changes: 6 additions & 0 deletions packages/react-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4dfb0fc

Please sign in to comment.