From f0f78a6126edd82c5fd6f749e8f3e83ccaeefd2c Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Fri, 24 Apr 2026 20:31:32 +0200 Subject: [PATCH] fix: resolve Uncaught TypeError: Cannot read properties of undefined (reading 'key') by ensuring usePersistentState handles functional updates safely --- src/contexts/FilterContext.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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]; }