GeoJSON
components does not seem to have an onClick
handler, global to the component. If you add onClick
, it will work, but TypeScript will trigger an error.
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. Maybe I should use a ref
? Adding a wrapper div
doesn't work.
How to set a global onClick
handler to the GeoJSON
component?
Version: 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
. This is not the usual onClick
prop.
I couldn't find any clear documentation however.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.