import { useState, useEffect } from 'react'
import * as echarts from 'echarts'
import { useSize } from 'ahooks';
export default function useEcharts(element) {
    const [chart, setChart] = useState();

    const size = useSize(element);

    useEffect(() => {
        if (element) {
            const chart = echarts.init(element);
            setChart(chart);
        }
    }, [element]);

    useEffect(() => {
        if (chart && size) {
            chart.resize();
        }
    }, [size, chart])

    return chart;
}