mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-05 12:50:41 +08:00
feat: option to regenerate the answer after switching model (#98)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { defaultConfig, getUserConfig } from '../config/index.mjs'
|
||||
import Browser from 'webextension-polyfill'
|
||||
|
||||
export function useConfig(initFn) {
|
||||
const [config, setConfig] = useState(defaultConfig)
|
||||
useEffect(() => {
|
||||
getUserConfig().then((config) => {
|
||||
setConfig(config)
|
||||
if (initFn) initFn()
|
||||
})
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
const listener = (changes) => {
|
||||
const changedItems = Object.keys(changes)
|
||||
let newConfig = {}
|
||||
for (const key of changedItems) {
|
||||
newConfig[key] = changes[key].newValue
|
||||
}
|
||||
setConfig({ ...config, ...newConfig })
|
||||
}
|
||||
Browser.storage.local.onChanged.addListener(listener)
|
||||
return () => {
|
||||
Browser.storage.local.onChanged.removeListener(listener)
|
||||
}
|
||||
}, [config])
|
||||
return config
|
||||
}
|
||||
Reference in New Issue
Block a user