uiwjs / react-baidu-map

基于 React 封装的百度地图组件,支持 React Hook,帮助你轻松的接入地图到 React 项目中。
https://uiwjs.github.io/react-baidu-map
MIT License
222 stars 22 forks source link

使用useMarker后发现后台一直在刷警告 #322

Closed sunny-token closed 8 months ago

sunny-token commented 8 months ago

const icon = new BMap.Icon('http://developer.baidu.com/map/jsdemo/img/fox.gif', new BMap.Size(300, 157)); useMarker({ map, position: NJ, icon: icon }); 不使用icon没问题,使用了icon后,后台一直刷warring,麻烦看下是啥问题呢?

image

具体例子下面链接。 demo

sunny-token commented 8 months ago

@jaywcjlove 好像用了icon后会导致副作用一直在刷,能帮忙看下吗?

jaywcjlove commented 8 months ago

@sunny-token 如果你提供可以重现错误的示例,我可以帮你看看

sunny-token commented 8 months ago

我上面的demo链接就是例子哦,你帮忙看看呢

---原始邮件--- 发件人: @.> 发送时间: 2024年1月23日(周二) 晚上7:33 收件人: @.>; 抄送: @.**@.>; 主题: Re: [uiwjs/react-baidu-map] 使用useMarker后发现后台一直在刷警告 (Issue #322)

@sunny-token 如果你提供可以重现错误的示例,我可以帮你看看

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

jaywcjlove commented 8 months ago

@sunny-token 使用 useMemo 可以解决这个问题

const  icon = useMemo(() => {
    return new BMap.Icon(
      "http://developer.baidu.com/map/jsdemo/img/fox.gif",
      new BMap.Size(300, 157),
    );
}, [])
sunny-token commented 8 months ago

好的,我试试,谢谢

---原始邮件--- 发件人: @.> 发送时间: 2024年1月23日(周二) 晚上8:20 收件人: @.>; 抄送: @.**@.>; 主题: Re: [uiwjs/react-baidu-map] 使用useMarker后发现后台一直在刷警告 (Issue #322)

@sunny-token 使用 useMemo 可以解决这个问题 const icon = useMemo(() => { return new BMap.Icon( "http://developer.baidu.com/map/jsdemo/img/fox.gif", new BMap.Size(300, 157), ); }, [])

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

sunny-token commented 8 months ago

可以了,用usememo解决了