Closed magnusrodseth closed 1 year ago
Hi @magnusrodseth,
I assume the issue is with your React setup, not the GL JS. You can probably consider using Portals to render Mapbox Popup content instead of rendering the content as React root element.
Just so you know, this issue tracker is for reporting bugs and feature requests, so I'm closing the issue. Feel free to reopen if you have any questions. You might also consider posting your question to https://stackoverflow.com/questions/tagged/mapbox-gl-js to ask the community for help.
mapbox-gl-js version:
^2.13.0
Question
I have map with some markers that have a custom popover. This custom popover was implemented in the following way:
This works, but I get the following error in the browser console:
Of course, I want to use React 18's functionality. Hence, I'm trying to convert the creation of a popup node (
createPopupNode
) to usecreateRoot
instead ofReactDOM.render(...)
.I figured it would be something like the following:
This returned value would need to be passed into the
MapboxPopup
parameter, but this doesn't work. Specifically, the custom popup on the marker is completely empty. To me, this suggests that the DOM elementconst popupNode = document.createElement("div");
never renders with the<SensorMarkerPopover />
component.How do I use
createRoot
to render a custom popup for a marker?Links to related documentation
createRoot