https://kotlinlang.org logo
#compose
Title
# compose
f

Fabio Berta

01/20/2023, 12:46 PM
Hi, I have slider composable that has an internal mutable state for the position. In
onValueChangeFinished
I update the external position (it's a video and I don't want to constantly update the video position while the user is dragging). Now I need to sync the internal state with external one. I did a lot of React development in the past years and there you would use the
key
prop for this and set it to position. This would force the component to re-instantiate whenever it changes. In compose land, there is the
key
function which actually achieves the same (I tested it). But in the docs it's never really mentioned for that use case, only for the lists use case. Is it fine to use it to force a leave/enter composition or is that an anti-pattern?
In hindsight this approach is not good as you can pass keys to
remember
and it will re-create the remembered object when the keys change. nice!
2 Views