Skip to content

(with/without) useMemo, how to trigger getColor without creating new Layer #8873

Answered by Pessimistress
moong23 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is correct that you should always create a new layer instance.
Instantiating a layer is not expensive, updating attributes is. So the question you should be asking is not "how do I avoid creating new layers", but "how do I avoid recalculating color?"

In your code above, you are recalculating getColor for all layers on hover, even if their hover states are not changed. Better setup would be

          getColor: mapTotalData[index].bundleId === hoveredTrajectory	
              ? HIGHLIGHT_LAYER_COLOR  // use constant, not callback function
              : d => d.color,
          updateTriggers: {
            getColor: [mapTotalData[index].bundleId === hoveredTrajectory],  // only tri…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Pessimistress
Comment options

Answer selected by moong23
@moong23
Comment options

@moong23
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