javascript - 有谁知道为什么我的反应地图 gl 不起作用
问题描述
我想知道 react typescript 是否很好,所以我尝试了一下。我遇到了我从未遇到过的问题。
这是我的代码
function Map() {
const [viewport, setViewport] = useState({
width: 400,
height: 400,
latitude: 37.7577,
longitude: -122.4376,
zoom: 8
});
return (
<ReactMapGL
{...viewport}
mapboxApiAccessToken="API key here"
onViewportChange={(viewport: any) => setViewport(viewport)}
/>
);
}
这是我得到的错误
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
▶ 2 stack frames were collapsed.
(anonymous function)
C:/Users/User/Drive/Coding/src/components/interactive-map.js:287
284 |
285 | /* eslint-disable max-statements */
286 | const InteractiveMap = forwardRef((props, ref) => {
> 287 | const parentContext = useContext(MapContext);
288 | const controller = useMemo(() => props.controller || new MapController(), []);
289 | const eventManager = useMemo(
290 | () =>
我不确定可能是什么原因,所以如果您需要更多信息,请询问。
解决方案
推荐阅读
- python - 无论标签名称如何,都在 XML 文件的主标签中提取所有子标签的值
- javascript - Webpack 没有构建最新的更改
- ios - SwiftUI Published 变量不会触发 UI 更新
- swift - SwiftUI DatePicker 在选择具有封闭数据范围的默认值时返回错误时间
- amazon-web-services - 除非打开 SSH 端口,否则 AWS Session Manager 无法连接
- linux - 如何获取 Vimdiff 命令的退出代码,该代码给出两个比较文件是否相同的结果?
- c++ - Cpp 线程对象和 shared_ptr 问题
- linux - 在 Linux 中将模式文本从一个文件复制到另一个文件
- javascript - 节点js函数连接到postgres返回错误
- php - 在托管项目上的项目上上传 laravel 文件