diff --git a/src/contexts/FilterContext.tsx b/src/contexts/FilterContext.tsx index 6ba166e..a54b2bd 100644 --- a/src/contexts/FilterContext.tsx +++ b/src/contexts/FilterContext.tsx @@ -33,8 +33,11 @@ export function usePersistentState(key: string, defaultValue: T): [T, (value: const state = context.states[key] !== undefined ? context.states[key] : defaultValue; const setState = useCallback((value: T | ((prev: T) => T)) => { - context.setState(key, value); - }, [context, key]); + context.setState(key, (current: any) => { + const actualCurrent = current !== undefined ? current : defaultValue; + return typeof value === 'function' ? (value as any)(actualCurrent) : value; + }); + }, [context, key, defaultValue]); return [state, setState]; }