UNPKG

@d3vtool/hooks

Version:

Collection of custom React hooks to simplify tasks in your React projects.

20 lines (19 loc) 1.1 kB
import { Hub } from "../Hub/Hub"; import { UpdateStateAction } from "../Hub/useHub"; export type UseStoredHub<T> = [T, UpdateStateAction<T>]; /** * A custom hook that synchronizes a shared state hub with persistent storage (like localStorage or sessionStorage). * The state of the hub is stored and retrieved using a key in persistent storage, ensuring the hub state persists across reloads. * * @template T - The type of the state managed by the hub. * @param {string} key - The key used to store and retrieve the hub's state from persistent storage. * @param {Hub<T>} hub - The shared state hub to be synchronized with persistent storage. * @returns {UseStoredHub<T>} - Returns the synchronized hub along with any additional functionality for managing the stored state. * * @example * // Example usage of `useStoredHub` to synchronize a hub with localStorage: * const storedHub = useStoredHub('myHubKey', myHub); * * // The state of `myHub` will now persist in localStorage under the key 'myHubKey'. */ export declare function useStoredHub<T>(key: string, hub: Hub<T>): UseStoredHub<T>;