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:
Christopher committed 2020-12-13 21:59:10 +01:00
1 parent 08e21f4129
commit 3e03993d5b
5 files changed
+65 -34

No files matched your search

+7 -7
View File
@@ -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];