When do you use `derivedStateOf` vs computing ever...
# compose
r
When do you use
derivedStateOf
vs computing every refresh? How much calculation is a lot in a composable?
k

https://youtu.be/ahXLwg2JYpc?feature=shared&t=948

- this video is great way to understand when
derivedStateOf
should be used
🌟 1
👌 2
🙏 1
s
I've always seen people say that using derivedStateOf is orders of magnitude more expensive than just doing the calculation itself. So it's only worth it if the rate of change between the inputs and the output differ by a lot. "A lot" is arbitrary, but I really take it as a case by case basis. For example observing scroll state (changes every frame) and deriving something out of that is for example often the right approach. But if you share some example you got in mind it's gonna be easier to discuss.
r
Thanks for that video, the explanation is perfectly clear. It's really more like a
distinct
. In my case I was just implementing a template String of the quite-big kind (with dozens of variables) and was wondering what the correct way of handling that was: a big remember with a lot of keys, or maybe something else I didn't really understand like derivedStateOf, or maybe nothing and computing that String isn't that heavy