UNPKG

bananas-commerce-admin

Version:

What's this, an admin for apes?

31 lines (30 loc) 1.62 kB
/** * The `useStorage` hook is a generic hook for reactively storing state in a * similar fashion to reacts usual {@link useState} hook. There is however some * caveats which are good to keep in mind: * - Any value of type `T` needs to be JSON (de-)serializeable. That means * storing certain non-serializeable values can result in unexpected * behavior, for example storing `Date` objects will stringify them. * - Setting the value to `undefined` is equivalent to deleting the storage * entry, not storing an `undefined` value. The reasoning behind this is * that because JSON doesn't support `undefined` it should instead indicate * an `undefined` value. * - The hook is designed to listen to the global `storage` event which * should make state changes propagate within the same context. If the * storage is for example modified from another tab that change should * trigger a state update in the current tab too. The behaviour of this may * be browser dependant. */ export declare function useStorage<T>(storage: Storage, key: string, initial: T): [T, React.Dispatch<React.SetStateAction<T>>]; /** * A hook for storing react state in `localStorage`. * * @see useStorage */ export declare function useLocalStorage<T>(key: string, initial: T): [T, import("react").Dispatch<import("react").SetStateAction<T>>]; /** * A hook for storing react state in `sessionStorage`. * * @see useStorage */ export declare function useSessionStorage<T>(key: string, initial?: T): [T | undefined, import("react").Dispatch<import("react").SetStateAction<T | undefined>>];