diff --git a/src/hook.ts b/src/hook.ts index 9a64097..ee083c9 100644 --- a/src/hook.ts +++ b/src/hook.ts @@ -7,7 +7,7 @@ import { useCallback, useEffect, useRef, useState } from "react" import { BaseStorage, Storage, type StorageCallbackMap } from "./index" -type Setter = ((v?: T, isHydrating?: boolean) => T) | T +type Setter = ((v?: T, isHydrated?: boolean) => T) | T /** * isPublic: If true, the value will be synced with web API Storage @@ -92,6 +92,9 @@ export const useStorage = (rawKey: RawKey, onInit?: Setter) => { return () => { isMounted.current = false storageRef.current.unwatch(watchConfig) + if (onInit instanceof Function) { + setRenderValue(onInit) + } } }, [key, persistValue])