Skip to content

Commit 9ddc657

Browse files
Copilothotlong
andcommitted
fix: update adapter ref pattern in useSchemaPersistence for prop changes
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 132e73f commit 9ddc657

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/react/src/hooks/useSchemaPersistence.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ export function createLocalStorageAdapter(prefix = 'objectui-schema'): SchemaPer
125125
export function useSchemaPersistence(
126126
adapter?: SchemaPersistenceAdapter,
127127
): SchemaPersistenceResult {
128-
const adapterRef = useRef(adapter ?? createLocalStorageAdapter());
128+
const defaultAdapter = useRef(createLocalStorageAdapter());
129+
const adapterRef = useRef(adapter ?? defaultAdapter.current);
130+
// Keep the ref up to date if the adapter prop changes
131+
adapterRef.current = adapter ?? defaultAdapter.current;
129132
const [loading, setLoading] = useState(false);
130133
const [error, setError] = useState<Error | null>(null);
131134
const [isDirty, setIsDirty] = useState(false);

0 commit comments

Comments
 (0)