useRouterRefresh
Wait for the router to finish navigating before executing a callback.
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import useRouterRefresh from "@/hooks/use-router-refresh"; export default function Example() { const [isLoading, setIsLoading] = useState(false); const refresh = useRouterRefresh(); const handleClick = useCallback(async () => { setIsLoading(true); await refresh(); console.log("The router has finished navigating."); setIsLoading(false); }, [refresh]); return ( <Button onClick={handleClick} disabled={isLoading}> Copy </Button> ); }
Installation
1
npx shadcn add "https://registry.niels.foo/use-router-refresh.json"