fix(frontend): update theme context usage
- Add theme-context.tsx - Update ThemeToggle.tsx to use ThemeContext
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Moon, Sun } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { useTheme } from "@/components/theme-provider"
|
||||
import { useTheme } from "@/components/theme-context"
|
||||
|
||||
export function ThemeToggle() {
|
||||
const { theme, toggleTheme } = useTheme()
|
||||
|
||||
20
frontend/src/components/theme-context.tsx
Normal file
20
frontend/src/components/theme-context.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
export type Theme = "light" | "dark"
|
||||
|
||||
export interface ThemeContextType {
|
||||
theme: Theme
|
||||
setTheme: (theme: Theme) => void
|
||||
setThemeLocal: (theme: Theme) => void
|
||||
toggleTheme: () => void
|
||||
}
|
||||
|
||||
export const ThemeContext = createContext<ThemeContextType | undefined>(undefined)
|
||||
|
||||
export const useTheme = () => {
|
||||
const context = useContext(ThemeContext)
|
||||
if (context === undefined) {
|
||||
throw new Error("useTheme must be used within a ThemeProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
Reference in New Issue
Block a user