import type { Graph as G6Graph } from '@antv/g6'; import { Graphin } from '@antv/graphin'; import classnames from 'classnames'; import type { PropsWithChildren } from 'react'; import React, { useEffect, useRef, useState } from 'react'; import { PREFIX } from '../../constants'; import { useDataset, useGraph, useGraphOptions } from '../../hooks'; import './index.less'; export interface GraphContainerProps extends Pick, 'id' | 'className' | 'style'> {} export const GraphContainer: React.FC> = (props) => { const { className, style, children } = props; const [options, setOptions] = useGraphOptions(); const [, setGraphInstance] = useGraph(); const [isReady, setIsReady] = useState(false); const [dataset] = useDataset(); const graphRef = useRef(null); useEffect(() => { if (!isReady || !graphRef.current || graphRef.current.destroyed) return; setGraphInstance(graphRef.current); }, [isReady]); useEffect(() => { setOptions({ data: dataset.data }); }, [dataset]); return (
setIsReady(true)}> {children}
); };