/ frontend / src / app / contexts / SettingsContext.js
SettingsContext.js
 1  import { createContext, useState } from "react";
 2  import merge from "lodash/merge";
 3  
 4  import { MatxLayoutSettings } from "app/components/MatxLayout/settings";
 5  
 6  export const SettingsContext = createContext({
 7    settings: MatxLayoutSettings,
 8    updateSettings: () => {}
 9  });
10  
11  export default function SettingsProvider({ settings, children }) {
12    const [currentSettings, setCurrentSettings] = useState(settings || MatxLayoutSettings);
13  
14    const handleUpdateSettings = (update = {}) => {
15      const marged = merge({}, currentSettings, update);
16      setCurrentSettings(marged);
17    };
18  
19    return (
20      <SettingsContext.Provider
21        value={{ settings: currentSettings, updateSettings: handleUpdateSettings }}>
22        {children}
23      </SettingsContext.Provider>
24    );
25  }