I’ve been using the <arcgis-map> component in a bunch of my React apps, and overall it works really well. But I’ve noticed something odd (and a bit frustrating) when the component is removed from the page.
Whenever the map component is unmounted or replaced, it calls the destroy method on the MapView. That makes sense on its own—but it also ends up destroying other ArcGIS API objects that I created separately, like Popup or FeatureLayer instances. Even though I created those outside of the component, they still get wiped out.
This has caused a few headaches. I often want to reuse things like a popup or a layer across multiple maps or views, kind of like singletons. But because the map component destroys them when it unmounts, I’m forced to recreate everything from scratch every time. That feels inefficient and makes my React code more complicated than it needs to be.
So I’m wondering:
Is this expected behaviour?
Is there a way to stop <arcgis-map> from destroying things I created outside of it?
Or is there a better pattern for reusing API instances safely?
Thanks in advance—keen to hear how others are handling this!
Solved! Go to Solution.
Great question, as this has come up a couple of times.
Great question, as this has come up a couple of times.
Thanks Rene - that will simplify things considerably!