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`, {