在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 id='chart' style={{width: 300, height: 200}}></div> </div> );
}