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