diff --git a/src/hook.ts b/src/hook.ts index a075dee..7911fba 100644 --- a/src/hook.ts +++ b/src/hook.ts @@ -24,7 +24,30 @@ export type RawKey = * @param onInit If it is a function, the returned value will be rendered and persisted. If it is a static value, it will only be rendered, not persisted * @returns */ -export const useStorage = (rawKey: RawKey, onInit?: Setter) => { +export function useStorage( + rawKey: RawKey, + onInit: Setter +): [ + T, + (setter: Setter) => Promise, + { + readonly setRenderValue: React.Dispatch> + readonly setStoreValue: (v: T) => Promise + readonly remove: () => void + } +] +export function useStorage( + rawKey: RawKey +): [ + T | undefined, + (setter: Setter) => Promise, + { + readonly setRenderValue: React.Dispatch> + readonly setStoreValue: (v?: T) => Promise + readonly remove: () => void + } +] +export function useStorage(rawKey: RawKey, onInit?: Setter) { const isObjectKey = typeof rawKey === "object" const key = isObjectKey ? rawKey.key : rawKey