Is rerendering all layers efficient in react or is there a better way? #5593
-
I am using deck.gl with react-map-gl to allow users to select cities from a list and be able to view boundaries of those cities. I keep track of the state of my city related form data using formik. I am new to deck.gl but my main drive to use it was to ensure I can be as performant as possible given how big the data and visualizations can become. I have been reading up the docs and also looking at both the issues and discussions tab here but I am still a little lost on whether my approach is correct or if I'm actually doing this all wrong. This is what my Map component looks like:
This works fine, however, it re-renders all layers on a change. Initially what made the most intuitive sense was to hide/show layers based on state change and I came across the Can anyone help me understand and/or nudge me about what I might be doing wrong/right here? Greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @kamrankhanwastaken! It re-renders all layers on every change, because you're removing all layers in every change. I would recommend you to have only one GeoJsonLayer and you pass it a FeatureCollection GeoJSON with all the city boundaries that you want to choose. The
I haven't tested this code, but it should work. deck.gl won't repeat Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
Thank you Clebel! I did test the code and it does exactly that. My following question is just regarding performance. Is this definitely better than say recreating all the layers? The only way I'm able to tell right now whether I'm in the wrong if when my browser crashes. Thank you again! |
Beta Was this translation helpful? Give feedback.
Hi @kamrankhanwastaken! It re-renders all layers on every change, because you're removing all layers in every change. I would recommend you to have only one GeoJsonLayer and you pass it a FeatureCollection GeoJSON with all the city boundaries that you want to choose. The
getFillColor
should be updated to make it a function to customise the fill color for each polygon.