Marko Novakovic
11/26/2021, 8:25 PMMap
like: mutableStateOf(map)
and reassigning that Map
doesn’t trigger recomposition? how can I approach this?Teodor Penkov
11/26/2021, 8:26 PMMarko Novakovic
11/26/2021, 8:26 PMMap<enum class, Double>
John O'Reilly
11/26/2021, 8:27 PMMarko Novakovic
11/26/2021, 8:28 PMTeodor Penkov
11/26/2021, 8:28 PMJohn O'Reilly
11/26/2021, 8:28 PMmutableStateOf
value?Marko Novakovic
11/26/2021, 8:30 PMMarko Novakovic
11/26/2021, 8:33 PMIf someone sent you a link to this post as a reply to a question on Slack or somewhere, and you just want a quick answer, here you go:
Don't put mutable collections inside mutable state holders.
hahahahaeygraber
11/26/2021, 9:01 PMvar map by mutableStateOf(mutableMapOf(1 to 2))
map = mutableMapOf(2 to 1)
That doesn't cause recomposition?Marko Novakovic
11/27/2021, 9:55 AMprivate val _map = mutableMapOf()
val map by mutableStateOf(map)
.....
_map[key] = value
map = HashMap(_map)
the gist of what am doing
it does’t trigger recompositionMarko Novakovic
11/27/2021, 9:56 AMHashMap
just map = _map
but that doesn’t work either
I introduced HashMap
in hope that creating new object will workphilglass
11/28/2021, 9:50 PMMutableState<MutableMap<X, Y>>
. The value you're assigning to map
is equal to its current value (in this case "deep equal", not reference equal, but the effect is the same), so by design no change notifications are sent.Marko Novakovic
11/29/2021, 7:46 AMMarko Novakovic
11/29/2021, 7:47 AMSideEffect
and it actually triggers on every change so I added remember(state.map) { mutableStateOf(state.map) }
and everything works