ElemeFE / ElemeFE/react-amap

在使用router 切换时,发生了Uncaught (in promise) TypeError: Cannot read property 'setterMap' of null错误

Open
#242 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
148
PR merge metrics
No merged PRs in 30d

Description

+ [x] 我已经搜索过 issue,没有类似的问题,或者类似的问题仍然没有解决方案。
+ [x] 我已经搜索过[文档](https://elemefe.github.io/react-amap/articles/start),并且仍然没有找到解决方案。
+ [x] 我写了个问题重现的例子,链接或者代码将会贴在下面。

#### Reproduce Example Link or Code Fragment
该组件位于 路由中
```typescript

const MyMap: React.FC = ({ position, onClick }) => {
const [ranging, setRanging] = useState(false);
const [rule, setRule] = useState({});
const style = useStyles();
const plugins: any = [
'Scale',
'OverView',
// v1.1.0 新增
'ControlBar',
'ToolBar',
];
const events = {
click: (map: any) => {
onClick(map);
},
created(instance: any) {
window.AMap.plugin(['AMap.RangingTool'], () => {
const rule = new window.AMap.RangingTool(instance, getMapPlugins());
setRule(rule);
});
},
};
useEffect(() => {
if (!rule.turnOn) {
return;
}
if (ranging) {
rule.turnOn();
} else {
rule.turnOff();
}
}, [rule, ranging]);
return (



}
center={position}
events={events}
>


setRanging(true)}>
开启测距

setRanging(false)}>
结束测距



);
};

export default MyMap;

```

#### What is actually happening?
在切换组件的时候发生了如下错误
![image](https://user-images.githubusercontent.com/51266600/108849947-ba7fd100-761d-11eb-8cbb-b38c9756d1a4.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.