diff --git a/src/components/ThemeProvider.tsx b/src/components/ThemeProvider.tsx
index 8fdf742..078d4c3 100644
--- a/src/components/ThemeProvider.tsx
+++ b/src/components/ThemeProvider.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react"
-import { Theme, ThemeProviderContext } from "@/lib/theme-context"
+import { type Theme, ThemeContext } from "@/lib/ThemeContext"
type ThemeProviderProps = {
children: React.ReactNode
@@ -61,9 +61,9 @@ export function ThemeProvider({
}
return (
-
+
{children}
-
+
)
}
diff --git a/src/hooks/useTheme.ts b/src/hooks/useTheme.ts
index 937d68c..be0c18d 100644
--- a/src/hooks/useTheme.ts
+++ b/src/hooks/useTheme.ts
@@ -1,11 +1,13 @@
import { useContext } from "react"
-import { ThemeProviderContext } from "@/lib/theme-context"
+import { ThemeContext, type ThemeContextType } from "@/lib/ThemeContext"
-export const useTheme = () => {
- const context = useContext(ThemeProviderContext)
+/** Hook to get and set the active theme. */
+export function useTheme(): ThemeContextType {
+ const context = useContext(ThemeContext);
- if (context === undefined)
- throw new Error("useTheme must be used within a ThemeProvider")
+ if (!context) {
+ throw new Error("useTheme must be used within a ThemeProvider");
+ }
- return context
+ return context;
}
\ No newline at end of file
diff --git a/src/lib/ThemeContext.ts b/src/lib/ThemeContext.ts
new file mode 100644
index 0000000..902edf9
--- /dev/null
+++ b/src/lib/ThemeContext.ts
@@ -0,0 +1,15 @@
+import { createContext } from "react";
+
+export type Theme = "dark" | "light" | "system";
+
+export type ThemeContextType = {
+ theme: Theme;
+ setTheme: (theme: Theme) => void;
+};
+
+const initialState: ThemeContextType = {
+ theme: "system",
+ setTheme: () => undefined,
+};
+
+export const ThemeContext = createContext(initialState);
\ No newline at end of file
diff --git a/src/lib/theme-context.ts b/src/lib/theme-context.ts
deleted file mode 100644
index 638a1cc..0000000
--- a/src/lib/theme-context.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { createContext } from "react";
-
-export type Theme = "dark" | "light" | "system";
-
-export type ThemeProviderState = {
- theme: Theme;
- setTheme: (theme: Theme) => void;
-};
-
-const initialState: ThemeProviderState = {
- theme: "system",
- setTheme: () => null,
-};
-
-export const ThemeProviderContext = createContext(initialState);
\ No newline at end of file