[英]React-leaflet GeoJSON `onClick`
GeoJSON
components does not seem to have an onClick
handler, global to the component. GeoJSON
组件似乎没有onClick
处理程序,对组件是全局的。 If you add onClick
, it will work, but TypeScript will trigger an error.如果添加onClick
,它会工作,但 TypeScript 会触发错误。
Sample code:示例代码:
import { GeoJSON } from "react-leaflet";
const MyComponent = () => (
<GeoJSON
key={id}
onClick={console.log}
data={geometry}
/>
)
Same question applies to style
by the way, there does not seem to be a way to have a global style.顺便说一句,同样的问题也适用于style
,似乎没有办法拥有全局风格。 Maybe I should use a ref
?也许我应该使用ref
? Adding a wrapper div
doesn't work.添加包装器div
不起作用。
How to set a global onClick
handler to the GeoJSON
component?如何为GeoJSON
组件设置全局onClick
处理程序?
Version: react-leaflet@2.7.0
版本: react-leaflet@2.7.0
And I've found the answer as soon as I've asked the question: it is onclick
, lowercase, not onClick
.我一问问题就找到了答案:它是onclick
,小写,而不是onClick
。 This is not the usual onClick
prop.这不是通常的onClick
道具。
I couldn't find any clear documentation however.但是,我找不到任何明确的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.