mirror of
https://github.com/khairul169/vaulterm.git
synced 2025-06-17 17:19:37 +07:00
30 lines
696 B
TypeScript
30 lines
696 B
TypeScript
|
import { create } from "zustand";
|
||
|
import { persist, createJSONStorage } from "zustand/middleware";
|
||
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||
|
|
||
|
type Store = {
|
||
|
theme: "light" | "dark";
|
||
|
setTheme: (theme: "light" | "dark") => void;
|
||
|
toggle: () => void;
|
||
|
};
|
||
|
|
||
|
const useThemeStore = create(
|
||
|
persist<Store>(
|
||
|
(set) => ({
|
||
|
theme: "light",
|
||
|
setTheme: (theme: "light" | "dark") => {
|
||
|
set({ theme });
|
||
|
},
|
||
|
toggle: () => {
|
||
|
set((state) => ({ theme: state.theme === "light" ? "dark" : "light" }));
|
||
|
},
|
||
|
}),
|
||
|
{
|
||
|
name: "theme",
|
||
|
storage: createJSONStorage(() => AsyncStorage),
|
||
|
}
|
||
|
)
|
||
|
);
|
||
|
|
||
|
export default useThemeStore;
|