fix: update feature flags on update (#4613)
This commit is contained in:
parent
7848ad86bd
commit
a6c1c49f98
@ -1,5 +1,4 @@
|
||||
import { useAtom } from 'jotai'
|
||||
import { atomWithStorage, useAtomValue } from 'jotai/utils'
|
||||
import { atomWithStorage, useAtomValue, useUpdateAtom } from 'jotai/utils'
|
||||
import { createContext, ReactNode, useCallback, useContext } from 'react'
|
||||
export { FeatureFlag } from './flags/featureFlags'
|
||||
|
||||
@ -23,14 +22,16 @@ export function useFeatureFlagsContext(): FeatureFlagsContextType {
|
||||
export const featureFlagSettings = atomWithStorage<Record<string, string>>('featureFlags', {})
|
||||
|
||||
export function useUpdateFlag() {
|
||||
const [featureFlags, setFeatureFlags] = useAtom(featureFlagSettings)
|
||||
const setFeatureFlags = useUpdateAtom(featureFlagSettings)
|
||||
|
||||
return useCallback(
|
||||
(featureFlag: string, option: string) => {
|
||||
featureFlags[featureFlag] = option
|
||||
setFeatureFlags(featureFlags)
|
||||
setFeatureFlags((featureFlags) => ({
|
||||
...featureFlags,
|
||||
[featureFlag]: option,
|
||||
}))
|
||||
},
|
||||
[featureFlags, setFeatureFlags]
|
||||
[setFeatureFlags]
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user