mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(settings): using local storage to save settings
Need to ensure that when a new setting is set, we re-render the phone.
This commit is contained in:
1 parent
08e21f4129
commit
3e03993d5b
5 files changed
+65
-34
No files matched your search
@@ -1,19 +1,19 @@
|
||||
import Default from "../default.json";
|
||||
import { atom, useRecoilState } from "recoil";
|
||||
import Default from '../default.json';
|
||||
import { atom, useRecoilState } from 'recoil';
|
||||
import useLocalStorage from '../../os/phone/hooks/useLocalStorage';
|
||||
|
||||
const configState = atom({
|
||||
key: "config",
|
||||
key: 'config',
|
||||
default: Default,
|
||||
});
|
||||
|
||||
export const useConfig = (state: any = configState): any => {
|
||||
const [, setVal] = useLocalStorage();
|
||||
const [config, _setConfig] = useRecoilState(state);
|
||||
|
||||
const setConfig = (key, value) => {
|
||||
_setConfig((oldConfig) => ({
|
||||
...oldConfig,
|
||||
[key]: value,
|
||||
}));
|
||||
console.log(`setConfig: ${key} ${value}`);
|
||||
setVal(key, value);
|
||||
};
|
||||
|
||||
return [config, setConfig];
|
||||
|
||||
Reference in new issue
Block a user