Skip to content

Commit

Permalink
fix: when => condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Feb 7, 2023
1 parent dd2afb8 commit e57b422
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/react-router/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ declare module '@tanstack/router' {

export type PromptProps = {
message: string
when?: boolean | any
condition?: boolean | any
children?: ReactNode
}

Expand Down Expand Up @@ -719,11 +719,14 @@ export function ErrorComponent({ error }: { error: any }) {
)
}

export function useBlocker(message: string, when: boolean | any = true): void {
export function useBlocker(
message: string,
condition: boolean | any = true,
): void {
const router = useRouter()

React.useEffect(() => {
if (!when) return
if (!condition) return

let unblock = router.history.block((retry, cancel) => {
if (window.confirm(message)) {
Expand All @@ -738,7 +741,7 @@ export function useBlocker(message: string, when: boolean | any = true): void {
})
}

export function Block({ message, when, children }: PromptProps) {
useBlocker(message, when)
export function Block({ message, condition, children }: PromptProps) {
useBlocker(message, condition)
return (children ?? null) as ReactNode
}

0 comments on commit e57b422

Please sign in to comment.