react event 防抖传参

  // echarts图表设置完毕后,添加事件监听,才用lodash.js的防抖函数
  useEffect(() => {
    
    const zrMouseMove = (event) => {
      console.log('[测试]event', event.event.x, event.event.y, event);
    };
    const zrMouseMoveFn = _.debounce(zrMouseMove,100)

    if (chartObjRef.current) {
      chartObjRef.current.getZr().on('mousemove', zrMouseMoveFn);
    }
    return () => {
      chartObjRef.current.getZr().off('mousemove', zrMouseMoveFn);
    }
  }, [chartObjRef?.current)

 

posted @ 2023-01-11 17:06  最好的年纪  阅读(117)  评论(0编辑  收藏  举报