BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/guarahooks/use-page-leave-demo

UsePageLeaveDemo

guarahooks/use-page-leave-demo
FreeExample

use-page-leave's hook in action.

Install it

npx shadcn@latest add https://guarahooks.com/r/use-page-leave-demo.json

Source

registry/example/use-page-leave-demo.tsxguarahooks.com/r/use-page-leave-demo.json
1'use client';
2
3import React, { useEffect } from 'react';
4
5import { Badge } from '@/components/ui/badge';
6import { Button } from '@/components/ui/button';
7import {
8 Card,
9 CardContent,
10 CardDescription,
11 CardFooter,
12 CardHeader,
13 CardTitle,
14} from '@/components/ui/card';
15
16import { cn } from '@/lib/utils';
17
18import { usePageLeave } from '@/hooks/guarahooks/use-page-leave';
19
20export default function UsePageLeaveDemo() {
21 const { isPageLeft, onPageLeave } = usePageLeave({
22 showConfirmation: true,
23 confirmationMessage:
24 'Are you sure you want to leave? Unsaved changes may be lost.',
25 });
26
27 useEffect(() => {
28 onPageLeave(() => {
29 // Custom action when the user leaves the page (tab switch)
30 // Example: save draft, send telemetry, etc.
31 // Replace this with whatever logic you need
32 // eslint-disable-next-line no-console
33 console.log('User left the page (tab switch)');
34 });
35 }, [onPageLeave]);
36
37 return (
38 <Card className="relative max-w-sm w-full">
39 <CardHeader>
40 <CardTitle>usePageLeave</CardTitle>
41 <CardDescription>
42 This component demonstrates the <code>usePageLeave</code> hook to
43 detect when the user switches tabs or tries to leave the page.
44 </CardDescription>
45 </CardHeader>
46 <CardContent className="space-y-4">
47 <Badge
48 variant="secondary"
49 className={cn(
50 'w-fit',
51 isPageLeft
52 ? 'bg-yellow-500/30 border-yellow-500 text-yellow-700'
53 : 'bg-green-500/30 border-green-500 text-green-700',
54 )}
55 >
56 {isPageLeft
57 ? 'You left the page (tab in background)'
58 : 'You are viewing this page'}
59 </Badge>
60 <p className="text-sm text-muted-foreground">
61 Open another tab or minimize the browser to see the status change.
62 <br />
63 Also try closing or reloading the page to see the confirmation alert.
64 </p>
65 </CardContent>
66 <CardFooter>
67 <Button
68 size="sm"
69 variant="outline"
70 onClick={() => window.location.reload()}
71 >
72 Reload page
73 </Button>
74 </CardFooter>
75 </Card>
76 );
77}

What it pulls in

Other registry items

  • card
  • button
  • badge
  • https://guarahooks.com/r/use-page-leave.json

Files it writes

  • registry/example/use-page-leave-demo.tsx

Facts

Registry
guarahooks
Type
registry:example
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-10
Last confirmed
today

Go to the source

guarahooks.com h3rmel/guarahooks on GitHub Raw registry item This item as JSON

More from guarahooks

All 100 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
UseAbortControllerDemouse-abort-controller-demoguarahooksExamplesFreeno deps
UseArrayStateDemouse-array-state-demoguarahooksExamplesFreeno deps
UseAxiosDemouse-axios-demoguarahooksExamplesFreeno deps
UseBatteryStatusDemouse-battery-status-demoguarahooksExamplesFreeno deps
UseBetterAuthDemouse-better-auth-demoguarahooksExamplesFreeno deps
UseClickOutsideDemouse-click-outside-demoguarahooksExamplesFreeno deps
UseConfirmDemouse-confirm-demoguarahooksExamplesFreeno deps
UseCookieDemouse-cookie-demoguarahooksExamplesFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex