I've got a silly question. I have a state that have a default value passed as parameter. In general, I want to be managed inside the component, but if the default value is changed, I wand inner state to be reset to the new default value. Which is the simplest way to do that?
altavir
09/13/2022, 3:17 PM
Construct like this works, but it looks ugly:
Copy code
var cachedValue by remember { mutableStateOf(initialViewPoint) }
var viewPoint by remember { mutableStateOf(initialViewPoint) }
if (cachedValue != initialViewPoint) {
viewPoint = initialViewPoint
cachedValue = initialViewPoint
}