Bin
2025-12-17 1d710f844b65d9bfdf986a71a3b924cd70598a41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { createContext, useContext, useMemo, useState } from "react";
 
export const ConfigContext = createContext(window.APP_SETTINGS);
ConfigContext.displayName = "ConfigContext";
 
export const ConfigConsumer = ConfigContext.Consumer;
 
export const ConfigProvider = ({ children }) => {
  const [config, setConfig] = useState(window.APP_SETTINGS ?? {});
 
  const update = (newConfig) => {
    if (!newConfig) return;
 
    setConfig(newConfig);
  };
 
  const contextValue = useMemo(() => {
    return {
      ...config,
      update,
    };
  }, [config]);
 
  return <ConfigContext.Provider value={contextValue}>{children}</ConfigContext.Provider>;
};
 
export const useConfig = () => {
  return useContext(ConfigContext);
};