(with/without) useMemo, how to trigger getColor without creating new Layer #8873
-
situationwant to update the color of the trajectoryLayer (pathLayer) if functions needs to be implemented
So my questions are,
|
Beta Was this translation helpful? Give feedback.
Answered by
Pessimistress
May 7, 2024
Replies: 1 comment 3 replies
-
self answer since creating layer isn't expensive, rather than using useMemo, just decided to create a new layer https://deck.gl/docs/developer-guide/using-layers#creating-layer-instances-is-cheap (let me know if I'm wrong) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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