Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-query): export QueryErrorResetBoundaryFunction #8089

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading