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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM