react hooks使用echarts5

在react hooks5使用echarts5有可能会抛出 警告

使用useRef来解决

function Demo() {
const dom = useRef(); useEffect(() => { if(!dom.current) { dom.current = echarts.init(document.getElementById('chart')); } console.log(dom.current, 'current'); dom.current.setOption({ xAxis: { type: 'category', data: ['a', 'b', 'c', 'd'] }, yAxis: { type: 'value' }, series: [{ type: 'line', data: [10, 12, 6, 9] }] }) }, [dom]); return ( <div> <span>count = {count}</span> <Button onClick={handlerAdd}>add</Button> <div style={{width: 300, height: 200}}></div> </div> );
}