24 lines
586 B
TypeScript
24 lines
586 B
TypeScript
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
import { create } from 'zustand'
|
|
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
|
|
export type ThemeScheme = 'light' | 'dark' | 'auto'
|
|
|
|
interface AppState {
|
|
themeScheme: ThemeScheme
|
|
setThemeScheme: (theme: ThemeScheme) => void
|
|
}
|
|
|
|
export const useAppStore = create<AppState>()(
|
|
persist(
|
|
set => ({
|
|
themeScheme: 'auto',
|
|
setThemeScheme: theme => set({ themeScheme: theme }),
|
|
}),
|
|
{
|
|
name: 'app-storage',
|
|
storage: createJSONStorage(() => AsyncStorage),
|
|
},
|
|
),
|
|
)
|