Skip to content

Commit a0fcf1d

Browse files
Updated providers.tsx
- Updated to prevented ThemeProvider from rendering during SSR to avoid hydration error.
1 parent 95b6379 commit a0fcf1d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/providers/providers.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22

33
import { ThemeProvider } from "@/providers/theme-provider";
44
import ReactQueryProvider from "@/providers/react-query-provider";
5+
import { useState, useEffect } from "react";
56

67
export function Providers({ children }: { children: React.ReactNode }) {
8+
const [mounted, setMounted] = useState(false);
9+
10+
useEffect(() => {
11+
setMounted(true);
12+
}, []);
13+
14+
if (!mounted) {
15+
return <>{children}</>; // Render children without ThemeProvider during SSR
16+
}
17+
718
return (
819
<ThemeProvider
920
attribute="class"

0 commit comments

Comments
 (0)