I'm working with `SnapshotStateMap<String, Any&...
# compose
l
I'm working with
SnapshotStateMap<String, Any>
and storing the value in a state object:
Copy code
// viewmodel content

private val state: SnapshotStateMap<String, Any> = mutableStateMapOf()
var myState by mutableStateOf(StateObject(state.getValue("key")))

@Immutable
data class StateObject(val value: Any)
I'm changing the values by bubbling up a
onValueChange
event that accesses
state
like state["key"] = newValue. But when I use for example a
Slider
composable and
onValueChange
is triggered, the Slider does not reflect the change, although I can print the new values. I guess storing the value in a state object as intermediate step is the problem. Is this intended or do I miss something here?
n
You probably want to use derivedStateOf.
Copy code
val keyState by remember(state) {
    derivedStateOf { StateObject(state.getValue("key")) }
}
Assuming you really need this intermediate step.