What is the proper / idiomatic way to update a sta...
# compose
t
What is the proper / idiomatic way to update a state in a class derived from another state without causing recomposition? Currently using something ugly like
Copy code
val value by remember { 
derivedStateOf { 
       otherstate.value = state.value + calculation
       otherstate.value
 } }
Wrapper { value }
With wrapper being a simple composable to avoid inlining and so only have it's content recomposed. If I do not read the value somewhere the derivedStateOf is not updated. I'm probably missing something obvious.
a
Why are you modifying
otherstate.value
here instead of defining this as
Copy code
val value by remember {
  derivedStateOf { state.value + calculation }
}
?
t
Because it's a state in a class that I use to have that state used upstream and downstream it's actually updated in the middle of the hierarchy and use before and after.
I've actually solved that by extracting the calculation to another composable and wrapped the call to that composable that read the state as a param.
The main pain point currently is that reading a state in a composable will recompose the whole composable and not just the function that use it as parameter. (I guess this is normal as hard to know the side effects probably)
And once everything recompose and performance issues arise it's really hard / impossible to find out what is causing the issue.