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-on-unmount-demo

UseOnUnmountDemo

guarahooks/use-on-unmount-demo
FreeExample

use-on-unmount's hook in action.

Live preview

live · rendered by the registry
Rendered by guarahooks on their own page — this is the component running, not a screenshot of it.

Install it

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

Source

registry/example/use-on-unmount-demo.tsxguarahooks.com/r/use-on-unmount-demo.json
1'use client';
2
3import React, { useState } from 'react';
4
5import { toast } from 'sonner';
6
7import { Button } from '@/components/ui/button';
8import {
9 Card,
10 CardContent,
11 CardDescription,
12 CardFooter,
13 CardHeader,
14 CardTitle,
15} from '@/components/ui/card';
16
17import { useOnUnmount } from '@/hooks/guarahooks/use-on-unmount';
18
19function ChildComponent() {
20 useOnUnmount(() => {
21 toast.success('Component unmounted successfully!');
22 });
23
24 return (
25 <div className="p-4 rounded-md bg-muted">
26 <p>I am the child component. Click to unmount me!</p>
27 </div>
28 );
29}
30
31export default function UseOnUnmountDemo() {
32 const [showChild, setShowChild] = useState(true);
33
34 return (
35 <Card className="relative max-w-md w-full">
36 <CardHeader>
37 <CardTitle>useOnUnmount</CardTitle>
38 <CardDescription>
39 This example uses the <code>useOnMount</code> hook to execute a
40 function only once when the component is mounted.
41 </CardDescription>
42 </CardHeader>
43 <CardContent>
44 <Button onClick={() => setShowChild((prev) => !prev)}>
45 {showChild ? 'Unmount child component' : 'Mount child component'}
46 </Button>
47 <div className="mt-6 min-h-[60px]">
48 {showChild && <ChildComponent />}
49 </div>
50 </CardContent>
51 <CardFooter>
52 <p className="text-muted-foreground text-sm">
53 When the child component is unmounted, a toast will be displayed using
54 shadcn/ui.
55 </p>
56 </CardFooter>
57 </Card>
58 );
59}

What it pulls in

Other registry items

  • card
  • button
  • sonner
  • https://guarahooks.com/r/use-on-unmount.json

Files it writes

  • registry/example/use-on-unmount-demo.tsx

Facts

Registry
guarahooks
Type
registry:example
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-03
Last confirmed
today

Go to the source

Docs on guarahooks 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
BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex