@tanstack/react-router 0.0.1-beta.76 → 0.0.1-beta.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +25 -27
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +24 -28
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +57 -57
- package/build/types/index.d.ts +3 -1
- package/build/umd/index.development.js +131 -52
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +23 -26
package/src/index.tsx
CHANGED
|
@@ -719,29 +719,26 @@ export function ErrorComponent({ error }: { error: any }) {
|
|
|
719
719
|
)
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
// usePrompt(message, when ?? true)
|
|
746
|
-
// return (children ?? null) as ReactNode
|
|
747
|
-
// }
|
|
722
|
+
export function useBlocker(message: string, when: boolean | any = true): void {
|
|
723
|
+
const router = useRouter()
|
|
724
|
+
|
|
725
|
+
React.useEffect(() => {
|
|
726
|
+
if (!when) return
|
|
727
|
+
|
|
728
|
+
let unblock = router.history.block((retry, cancel) => {
|
|
729
|
+
if (window.confirm(message)) {
|
|
730
|
+
unblock()
|
|
731
|
+
retry()
|
|
732
|
+
} else {
|
|
733
|
+
cancel()
|
|
734
|
+
}
|
|
735
|
+
})
|
|
736
|
+
|
|
737
|
+
return unblock
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export function Block({ message, when, children }: PromptProps) {
|
|
742
|
+
useBlocker(message, when)
|
|
743
|
+
return (children ?? null) as ReactNode
|
|
744
|
+
}
|