@meonode/ui
Version:
A structured approach to component composition, direct CSS-first prop styling, built-in theming, smart prop handling (including raw property pass-through), and dynamic children.
34 lines • 1.41 kB
TypeScript
import type { PortalHandle, PortalLayerProps } from '../types/node.type.js';
/**
* React hook for imperative portal control.
* Provides methods to open, update, and close portals from within the component tree.
* Must be used within a `PortalProvider`.
* @template T The type of data to be synchronized with the portal.
* @param data Optional data to keep in sync with the most recently opened portal.
* If provided, any changes to this data will automatically call `updateData`.
* @returns An object with:
* - `open(Component, initialData?)` — opens a portal layer and returns a PortalHandle
* - `updateData(next)` — pushes new data to the most recently opened portal
* - `close()` — closes the most recently opened portal
* - `handle` — ref to the current PortalHandle
* @example
* ```ts
* // With auto-sync
* const [count, setCount] = useState(0)
* const portal = usePortal({ count, setCount })
*
* const handleOpen = () => {
* portal.open(MyContent, { count, setCount })
* }
*
* // Without auto-sync
* const portal = usePortal()
* ```
*/
export declare function usePortal<T = any>(data?: T): {
open: <P = T>(Component: React.ComponentType<PortalLayerProps<P>>, initialData?: P) => PortalHandle<P>;
updateData: <T_1>(next: T_1) => void;
close: () => void;
handle: import("react").RefObject<PortalHandle<any> | null>;
};
//# sourceMappingURL=usePortal.d.ts.map