首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >mapbox-gl-draw用on绑定的事件在react中无法取消绑定?

mapbox-gl-draw用on绑定的事件在react中无法取消绑定?

提问于 2022-10-13 09:53:34
回答 0关注 0查看 49
代码语言:js
复制

 const drawPolygon = (index: number, callback: () => void) => () => {
 setIndex(index as number);
 draw?.changeMode('draw_polygon');
 mapInstance.on('draw.create', getEntity);
 mapInstance.on('draw.update', getEntity);
 callback?.();
  };
代码语言:js
复制
点击按钮触发drawPolygon事件,开始绘制面对象,
代码语言:js
复制
  const destroyInstance = () => {
    console.log('destroyInstance******');
    mapInstance.off('draw.create', getEntity);
    mapInstance.off('draw.update', getEntity);
  };

  React.useEffect(() => {
    destroyInstance();
    return () => {
      console.log('页面销毁....');
    };
  });
  //切换到别的组件,进行面绘制,发现当前组件的getEntity事件依然有输出,说明当前组件的未解绑,求解!!!

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档