Just be really sure it's set

This commit is contained in:
Eric Bailey
2025-08-11 14:15:57 -05:00
parent e911d29557
commit 09444add21
+12 -1
View File
@@ -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<Store>[Key]) => void,
] {
type Schema = StorageSchema<Store>
const initialized = useRef(false)
const [value, setValue] = useState<Schema[Key] | undefined>(() =>
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`, {