From 09444add2131299f2498268a32ed10a50432b49a Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 11 Aug 2025 14:15:57 -0500 Subject: [PATCH] Just be really sure it's set --- src/storage/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/storage/index.ts b/src/storage/index.ts index 663a273ea1..d503167ae7 100644 --- a/src/storage/index.ts +++ b/src/storage/index.ts @@ -1,4 +1,4 @@ -import {useCallback, useEffect, useState} from 'react' +import {useCallback, useEffect, useState, useRef} from 'react' import {MMKV} from 'react-native-mmkv' import {type Account, type Device} from '#/storage/schema' @@ -112,10 +112,21 @@ export function useStorage< (data: StorageSchema[Key]) => void, ] { type Schema = StorageSchema + const initialized = useRef(false) const [value, setValue] = useState(() => storage.get(scopes), ) + useEffect(() => { + if (!initialized.current) { + const raw = storage.get(scopes) + if (value !== raw) { + initialized.current = true + setValue(raw) + } + } + }, [value, scopes]) + useEffect(() => { const sub = storage.addOnValueChangedListener(scopes, () => { if (debug) logger.debug(`${debug} - storage change`, {