UNPKG

@mongez/react-atom

Version:

A simple state management tool for React Js.

40 lines 1.34 kB
import { type ReactAtom } from "./types"; export type PortalActions<T = any> = { /** * Opens the portal with optional data. * @param data - Optional data to be passed when opening the portal. */ open: (data?: T) => void; /** * Closes the portal. */ close: () => void; /** * Toggles the portal's open state. If the portal is closed, it opens with optional data. * If the portal is open, it closes. * @param data - Optional data to be passed when opening the portal. */ toggle: (data?: T) => void; /** * Hook to determine if the portal is currently open. * @returns A boolean indicating if the portal is open. */ useOpened: () => boolean; /** * Hook to retrieve the current data associated with the portal. * @returns The data associated with the portal. */ useData: () => T; }; type PortalData<T = any> = { opened: boolean; data: T; }; export type AtomPortal<T = any> = ReactAtom<PortalData<T>, PortalActions<T>>; /** * Create a portal atom * This atom is used to create a portal (a modal, a tooltip, a dropdown, etc.) */ export declare function portalAtom<T = any>(name: string, opened?: boolean): Atom<Value, import("./types").ReactActions<Value> & Actions>; export {}; //# sourceMappingURL=portal-atom.d.ts.map