Skip to content

Is rerendering all layers efficient in react or is there a better way? #5593

Answered by Clebal
kamrankhanwastaken asked this question in Q&A
Discussion options

You must be logged in to vote

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.

const Map = () => {
  const { values } = useFormikContext();
  const [layers, setLayers] = React.useState([]);

  const loadLayer = () => {
    Promise.all(
        values.locations.map((location, idx) => getPolygon(location.name, idx))
    ).then(features => {
        setLayers([
          new GeoJsonLayer({
            id:…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by kamrankhanwastaken
Comment options

You must be logged in to vote
2 replies
@Clebal
Comment options

@kamrankhanwastaken
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants