@tanstack/react-router 0.0.1-beta.77 → 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/src/index.tsx CHANGED
@@ -719,29 +719,26 @@ export function ErrorComponent({ error }: { error: any }) {
719
719
  )
720
720
  }
721
721
 
722
- // TODO: While we migrate away from the history package, these need to be disabled
723
- // export function usePrompt(message: string, when: boolean | any): void {
724
- // const router = useRouter()
725
-
726
- // React.useEffect(() => {
727
- // if (!when) return
728
-
729
- // let unblock = router.getHistory().block((transition) => {
730
- // if (window.confirm(message)) {
731
- // unblock()
732
- // transition.retry()
733
- // } else {
734
- // router.setStore((s) => {
735
- // s.currentLocation.pathname = window.location.pathname
736
- // })
737
- // }
738
- // })
739
-
740
- // return unblock
741
- // }, [when, message])
742
- // }
743
-
744
- // export function Prompt({ message, when, children }: PromptProps) {
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
+ }