Files
5chan/src/hooks/use-theme.ts
T

22 lines
535 B
TypeScript
Raw Normal View History

2024-02-28 21:18:37 +01:00
import { create, StoreApi } from 'zustand';
interface ThemeState {
theme: string;
setTheme: (theme: string) => void;
}
const useThemeStore = create<ThemeState>((set: StoreApi<ThemeState>['setState']) => ({
2024-03-15 22:42:13 +01:00
theme: localStorage.getItem('theme') || 'yotsuba',
2024-02-28 21:18:37 +01:00
setTheme: (theme: string) => {
localStorage.setItem('theme', theme);
set({ theme });
},
}));
const useTheme = (): [string, (theme: string) => void] => {
const { theme, setTheme } = useThemeStore();
return [theme, setTheme];
};
export default useTheme;