UseIntersectionObserverDemo
guarahooks/use-intersection-observer-demoFreeExample
use-intersection-observer's hook in action.
Install it
npx shadcn@latest add https://guarahooks.com/r/use-intersection-observer-demo.jsonSource
1'use client';23import React, { useRef } from 'react';45import { Button } from '@/components/ui/button';6import {7 Card,8 CardContent,9 CardDescription,10 CardFooter,11 CardHeader,12 CardTitle,13} from '@/components/ui/card';1415import { useIntersectionObserver } from '@/hooks/guarahooks/use-intersection-observer';1617export function UseIntersectionObserverDemo() {18 const targetRef = useRef<HTMLDivElement | null>(null);19 const { ref, entry, isIntersecting } =20 useIntersectionObserver<HTMLDivElement>({21 root: null,22 rootMargin: '0px',23 threshold: 0.1,24 });2526 return (27 <Card className="max-w-md w-full">28 <CardHeader>29 <CardTitle>Intersection Observer Demo</CardTitle>30 <CardDescription>31 Observe when the box enters/exits the viewport.32 </CardDescription>33 </CardHeader>34 <CardContent className="space-y-4">35 <div36 ref={(node) => {37 targetRef.current = node;38 ref(node);39 }}40 className="h-48 border-2 rounded-lg flex items-center justify-center"41 >42 {isIntersecting ? 'Visible' : 'Not Visible'}43 </div>44 <div>45 <p>Intersection Ratio: {entry?.intersectionRatio.toFixed(2)}</p>46 </div>47 </CardContent>48 <CardFooter>49 <Button variant="outline" onClick={() => ref(null)}>50 Reset Observer51 </Button>52 </CardFooter>53 </Card>54 );55}
What it pulls in
Other registry items
Files it writes
More from guarahooks
All 100 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| UseAbortControllerDemouse-abort-controller-demo | guarahooks | Examples | Free | no deps | |
| UseArrayStateDemouse-array-state-demo | guarahooks | Examples | Free | no deps | |
| UseAxiosDemouse-axios-demo | guarahooks | Examples | Free | no deps | |
| UseBatteryStatusDemouse-battery-status-demo | guarahooks | Examples | Free | no deps | |
| UseBetterAuthDemouse-better-auth-demo | guarahooks | Examples | Free | no deps | |
| UseClickOutsideDemouse-click-outside-demo | guarahooks | Examples | Free | no deps | |
| UseConfirmDemouse-confirm-demo | guarahooks | Examples | Free | no deps | |
| UseCookieDemouse-cookie-demo | guarahooks | Examples | Free | no deps |
