MCPcopy Create free account
hub / github.com/ChatGPTBox-dev/chatGPTBox / useConfig

Function useConfig

src/hooks/use-config.mjs:5–30  ·  view source on GitHub ↗
(initFn, ignoreSession = true)

Source from the content-addressed store, hash-verified

3import Browser from 'webextension-polyfill'
4
5export function useConfig(initFn, ignoreSession = true) {
6 const [config, setConfig] = useState(defaultConfig)
7 useEffect(() => {
8 getUserConfig().then((config) => {
9 setConfig(config)
10 if (initFn) initFn()
11 })
12 }, [])
13 useEffect(() => {
14 const listener = (changes) => {
15 if (ignoreSession) if (Object.keys(changes).length === 1 && 'sessions' in changes) return
16
17 const changedItems = Object.keys(changes)
18 let newConfig = {}
19 for (const key of changedItems) {
20 newConfig[key] = changes[key].newValue
21 }
22 setConfig({ ...config, ...newConfig })
23 }
24 Browser.storage.local.onChanged.addListener(listener)
25 return () => {
26 Browser.storage.local.onChanged.removeListener(listener)
27 }
28 }, [config])
29 return config
30}

Callers 6

FloatingToolbarFunction · 0.90
DecisionCardFunction · 0.90
ReadButtonFunction · 0.90
ConversationCardFunction · 0.90
AppFunction · 0.90
useThemeFunction · 0.90

Calls 1

getUserConfigFunction · 0.90

Tested by

no test coverage detected