@gravity-ui/graph
Version:
Modern graph editor component
25 lines (24 loc) • 948 B
TypeScript
import type { Graph } from "../../graph";
import type { Layer, LayerPublicProps } from "../../services/Layer";
/**
* Hook for managing graph layers.
*
* Provides a convenient way to add and manage layers in the graph.
* Automatically handles layer initialization and props updates.
* Uses deep props comparison to optimize re-renders.
*
* @example
* ```tsx
* const devToolsLayer = useLayer(graph, DevToolsLayer, {
* showRuler: true,
* rulerSize: 20,
* });
* ```
*
* @template T - Type of layer constructor extending Layer
* @param graph - Graph instance
* @param layerCtor - Layer class constructor
* @param props - Layer properties (excluding internal props like root, camera, graph, emitter)
* @returns Layer instance or null if graph is not initialized
*/
export declare function useLayer<T extends Constructor<Layer> = Constructor<Layer>>(graph: Graph | null, layerCtor: T, props: LayerPublicProps<T>): InstanceType<T>;