【发布时间】:2023-01-02 00:32:34
【问题描述】:
我正在尝试使用eventHandlers和react-leaflet在一个next.js应用程序,但事件永远不会被触发。
这是我在我的代码中使用的代码示例Map零件:
import { MapContainer, Rectangle } from "react-leaflet";
const Map = () => {
return (
<MapContainer center={[25, 25]} zoom={1} style={{ height: 600, width: 600 }}>
<Rectangle
bounds={[
[0, 0],
[50, 50],
]}
eventHandlers={{
click: () => console.log("clicked.."),
}}
/>
</MapContainer>
);
};
export default Map;
我试过在next.js应用程序(平面反应应用程序)并且它按预期工作,但是当我在next.js应用程序,该事件永远不会被触发。
这是我如何渲染的示例Map我的组件index.js文件:
import dynamic from "next/dynamic";
const Map = dynamic(() => import("../components/Map"), {
ssr: false,
});
export default function Home() {
return (
<>
<Map />
</>
);
}
我也试过在代码箱中使用这段代码,但我无法让沙箱工作(它崩溃了)。还在https://react-leaflet.js.org/docs/example-popup-marker/ 上的实时编辑器上对其进行了测试,并将标记替换为矩形组件,单击时触发事件。
有没有其他人遇到过这个问题并找到了解决方案?
在此先感谢您的帮助!
【问题讨论】:
标签: reactjs next.js react-leaflet react-leaflet-v4