UNPKG

@plasmohq/storage

Version:

Safely and securely store data and share them across your extension and websites

38 lines (35 loc) 1.2 kB
import { BaseStorage } from './index.cjs'; type Setter<T> = ((v?: T, isHydrated?: boolean) => T) | T; /** * isPublic: If true, the value will be synced with web API Storage */ type RawKey = string | { key: string; instance: BaseStorage; }; /** * https://docs.plasmo.com/framework/storage * @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 */ declare function useStorage<T = any>(rawKey: RawKey, onInit: Setter<T>): [ T, (setter: Setter<T>) => Promise<void>, { readonly setRenderValue: React.Dispatch<React.SetStateAction<T>>; readonly setStoreValue: (v: T) => Promise<null>; readonly remove: () => void; readonly isLoading: boolean; } ]; declare function useStorage<T = any>(rawKey: RawKey): [ T | undefined, (setter: Setter<T>) => Promise<void>, { readonly setRenderValue: React.Dispatch<React.SetStateAction<T | undefined>>; readonly setStoreValue: (v?: T) => Promise<null>; readonly remove: () => void; readonly isLoading: boolean; } ]; export { type RawKey, useStorage };