dev-resources.site
for different kinds of informations.
Handling Local Storage for Toaster Notifications
Published at
1/2/2025
Categories
webdev
javascript
shadcn
typescript
Author
brokarim
Author
8 person written this
brokarim
open
Demo :
Source code :
============= layout.tsx
<body>
<ThemeProvider attribute="class" defaultTheme="dark">
{children}
<DevToaster />
</ThemeProvider>
</body>
============= dev-toaster.tsx
export function TemplateToaster() {
const [isVisibile, setIsVisible] = useState(true);
const [notificationStatus, setNotificationStatus] = useState<string | null>(null);
const path = usePathname();
const [hydrated, setHydrated] = useState(false);
// Run this effect only once to set hydrated to true
useEffect(() => {
setHydrated(true);
}, []);
// Run this effect only on client side
useEffect(() => {
if (hydrated) {
// Remove the saved notification status to reset it
localStorage.removeItem("behindui-notification");
// Check localStorage after clearing
setNotificationStatus(localStorage.getItem("behindui-notification"));
}
}, [hydrated]);
if (!hydrated) {
return null;
}
const templates = path.includes("templates");
const isIframe = isInIframe();
if (isIframe || notificationStatus === "off") {
return <div></div>;
}
return (
isVisibile &&
!templates && (
<section className="relative z-50">
<div className="font-geist fixed bottom-4 right-4">
<Card className={cn(" w-[350px] bg-background [border:1px_solid_rgba(255,255,255,.1)]")}>
<CardHeader>
<div className="font-mono font-bold uppercase tracking-tight">
๐งWebsite Under Development ๐ง <br />
</div>
<CardDescription className="mt-4 text-black/90 dark:text-white/70">This website is currently in active development. Some features may be incomplete or not working as expected</CardDescription>
</CardHeader>
<CardFooter className="flex justify-end gap-4">
<Button
size="sm"
onClick={() => {
localStorage.setItem("behindui-notification", "off");
setIsVisible(false);
}}
>
Understand
</Button>
</CardFooter>
</Card>
</div>
</section>
)
);
}
function isInIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
shadcn Article's
30 articles in total
Made FOSS for simplifying NextJS dev with OAuth And Postgres
read article
.gitkeep file in Shadcn/ui source code
read article
Introducing the Zod Schema Designer: A Visual Tool for Creating and Editing Zod Schemas
read article
Handling Local Storage for Toaster Notifications
currently reading
I created a visually pleasing HTML color viewer
read article
AISEKA Color Tool Website
read article
Color Palette is served with ShadCn Theme Editor
read article
Create React project with Vite and set up Tailwind, shadcn/ui
read article
Why Developers Love the Shadcn Sidebar Component
read article
A comparison of metadata configurations between Lobechat and Shadcn/ui
read article
Forms in seconds with ShardCn forms
read article
What is the Difference Between Radix UI and ShadCN?
read article
How Shadcn CLI uses error constants to improve code readability
read article
Exploring the ShadCN UI Library: A Comprehensive Guide
read article
10 Essential Shadcn Components Every Developer Should Know About
read article
The beginning of my open source journey
read article
Install ShadCN and Tailwind in Vite React Project
read article
How to add shadcn to existing project
read article
How to Use Shadcn UI with a React Project
read article
How to Install Shadcn with Next.js 14: A Step-by-Step Guide
read article
Shadcn Date Picker with custom implementation
read article
How to Fix Shadcn UI Adding Wrong Folder for Components
read article
Material UI vs Shadcn
read article
Building UIs with Franken UI, a Shadcn alternative
read article
Implement ShadCn form with Validation
read article
Top 5 Coolest shadcn/ui Extensions
read article
Shadcn UI: Must-Have Tools & Resources
read article
shadcn-ui/ui codebase analysis: examples route explained.
read article
Two ways I discovered to pass dynamic parameters in (arrow and non-arrow) function.
read article
Creating a User Nav bar in Next.js 14 using Shadcn UI and Tailwindย CSS
read article
Featured ones: