import { Graph as G6Graph } from '@antv/g6'; import type { PropsWithChildren } from 'react'; import React, { CSSProperties, forwardRef, memo, useImperativeHandle } from 'react'; import { GraphinContext } from './context'; import useGraph from './hooks/useGraph'; import type { GraphinProps } from './types'; type GraphRef = G6Graph | null; /** * Graphin, the react component for G6. */ const Graph = forwardRef>((props, ref) => { const { style, children, ...restProps } = props; const { graph, containerRef, isReady } = useGraph(restProps); useImperativeHandle(ref, () => graph!, [graph]); const containerStyle: CSSProperties = { height: 'inherit', position: 'relative', ...style, }; if (children) { return (
{isReady && children}
); } return
; }); export const Graphin = memo(Graph);