feat: initial project scaffold with Watch companion app
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
|
||||
import { MMKV } from "react-native-mmkv";
|
||||
|
||||
const storage = new MMKV();
|
||||
|
||||
type SettingsContextType = {
|
||||
poolLength: number;
|
||||
setPoolLength: (length: number) => void;
|
||||
};
|
||||
|
||||
const SettingsContext = createContext<SettingsContextType>({
|
||||
poolLength: 25,
|
||||
setPoolLength: () => {},
|
||||
});
|
||||
|
||||
export function useSettings() {
|
||||
return useContext(SettingsContext);
|
||||
}
|
||||
|
||||
export function SettingsProvider({ children }: { children: ReactNode }) {
|
||||
const [poolLength, setPoolLengthState] = useState<number>(() => {
|
||||
const stored = storage.getNumber("poolLength");
|
||||
return stored ?? 25;
|
||||
});
|
||||
|
||||
const setPoolLength = (length: number) => {
|
||||
setPoolLengthState(length);
|
||||
storage.set("poolLength", length);
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsContext.Provider value={{ poolLength, setPoolLength }}>
|
||||
{children}
|
||||
</SettingsContext.Provider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user