ElemeFE / react-amap

基于 React 封装的高德地图组件。AMap Component Based On React.
https://elemefe.github.io/react-amap/articles/start
MIT License
1.03k stars 151 forks source link

fix: 修复 onInstanceCreated 在 ref 回调之前执行引起的报错 #232

Closed loveky closed 4 years ago

loveky commented 4 years ago

以 Polygon 为例,在 constructor 执行 13ms 之后调用initMapPolygon进而调用onInstanceCreated并不能保证高阶组件中的 ref 回调已经执行,因此执行 onInstanceCreated 时,this.myMapComponent 可能为 null. 因此考虑增加 this.myMapComponent 是否为空的判断,如果为空,则在 didMount 中执行 onInstanceCreated (ref 回调会保证在 didMount 之前执行)

loveky commented 4 years ago

@ioslh 帮忙review一下吧