UseNotificationsDemo
guarahooks/use-notifications-demoFreeExample
use-notifications's hook in action.
Install it
npx shadcn@latest add https://guarahooks.com/r/use-notifications-demo.jsonSource
1'use client';23import {4 AlertCircleIcon,5 BellIcon,6 CheckCircle2Icon,7 XCircleIcon,8} from 'lucide-react';910import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';11import { Badge } from '@/components/ui/badge';12import { Button } from '@/components/ui/button';13import {14 Card,15 CardContent,16 CardDescription,17 CardFooter,18 CardHeader,19 CardTitle,20} from '@/components/ui/card';2122import { useNotifications } from '@/hooks/guarahooks/use-notifications';2324export default function UseNotificationsDemo() {25 const {26 permission,27 requestPermission,28 showNotification,29 isSupported,30 isSecureContext,31 supportsActions,32 supportsBadge,33 supportsImage,34 supportsVibrate,35 supportsSound,36 } = useNotifications();3738 const handleRequestPermission = async () => {39 try {40 await requestPermission();41 } catch (error) {42 console.error('Failed to request permission:', error);43 }44 };4546 const handleShowNotification = () => {47 showNotification('Demo Notification', {48 body: 'This is a test notification from the demo component',49 icon: '/favicon.ico',50 badge: '/favicon.ico',51 image: '/favicon.ico',52 // Actions are only supported with Service Worker53 // actions: [54 // {55 // action: 'view',56 // title: 'View Details',57 // },58 // ],59 });60 };6162 return (63 <Card className="relative max-w-2xl w-full">64 <CardHeader>65 <CardTitle className="flex items-center gap-2">66 <BellIcon className="h-5 w-5" />67 useNotifications68 </CardTitle>69 <CardDescription>70 This component demonstrates the use of the{' '}71 <code>useNotifications</code> hook to manage browser notifications.72 </CardDescription>73 </CardHeader>74 <CardContent className="space-y-4">75 <div className="space-y-2">76 <h3 className="font-medium">Browser Support</h3>77 <div className="flex flex-wrap gap-2">78 <Badge variant={isSupported ? 'default' : 'destructive'}>79 {isSupported ? 'Supported' : 'Not Supported'}80 </Badge>81 <Badge variant={isSecureContext ? 'default' : 'destructive'}>82 {isSecureContext ? 'Secure Context' : 'Not Secure'}83 </Badge>84 </div>85 </div>8687 <div className="space-y-2">88 <h3 className="font-medium">Feature Support</h3>89 <div className="flex flex-wrap gap-2">90// … truncated
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 |
