Add config and settings!

This commit is contained in:
J Francisco Rader committed 2020-08-22 01:30:01 -03:00
1 parent 16004a9a86
commit 3900b9fa83
14 files changed
+90 -9

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
import { createContext, useContext, useEffect, useState } from "react";
import _set from "lodash/set";
import Default from "../default.json";
export const ConfigContext = createContext(Default);
export const useConfig = (Context = ConfigContext) => {
const configCtx = useContext(Context);
const [config, _setConfig] = useState({ ...configCtx });
useEffect(() => {
_setConfig({ ...configCtx });
}, [configCtx]);
const setConfig = (key, value) => {
const state = { ...config };
_setConfig(_set(state, key, value));
};
return [config, setConfig];
};