Moar debug
This commit is contained in:
+10
-3
@@ -113,14 +113,21 @@ export function useStorage<
|
|||||||
] {
|
] {
|
||||||
type Schema = StorageSchema<Store>
|
type Schema = StorageSchema<Store>
|
||||||
const initialized = useRef(false)
|
const initialized = useRef(false)
|
||||||
const [value, setValue] = useState<Schema[Key] | undefined>(() =>
|
const [value, setValue] = useState<Schema[Key] | undefined>(() => {
|
||||||
storage.get(scopes),
|
if (debug) logger.debug(`${debug} - init`, {
|
||||||
)
|
value: storage.get(scopes) ?? 'unset'
|
||||||
|
})
|
||||||
|
return storage.get(scopes)
|
||||||
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!initialized.current) {
|
if (!initialized.current) {
|
||||||
const raw = storage.get(scopes)
|
const raw = storage.get(scopes)
|
||||||
if (value !== raw) {
|
if (value !== raw) {
|
||||||
|
logger.debug(`${debug} - syncing initial`, {
|
||||||
|
value: value ?? 'unset',
|
||||||
|
raw: raw ?? 'unset',
|
||||||
|
})
|
||||||
initialized.current = true
|
initialized.current = true
|
||||||
setValue(raw)
|
setValue(raw)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user