I have a Google Map, and depending of a `mapState....
# compose
p
I have a Google Map, and depending of a
mapState.mapPois
list, I'm displaying the markers of the map:
Copy code
@Composable fun MapPanel(mapState: MapState, [...]) {
    GoogleMap() {
        for (busStop in mapState.busStops) { Marker([...]) }
The parametrized mapstate is collected like this on the parent composable:
val mapState by vm.mapState.collectAsStateWithLifecycle()
And is being stored as a state like this on the vm:
Copy code
data class MapState(val busStops: List<BusStop> = emptyList(),}
[...]
protected val _mapState = MutableStateFlow(MapState())
val mapState: StateFlow<MapState> = _mapState
When
mapState.busStop
list is modified on the vm, the map is not being recomposed:
Copy code
_mapState.update { currentState -> currentState.copy(busStops = favoriteBusStopsList) }
The only way I got the recomposition being triggered is embedding the for that iterates mapState.busStops into a
key(mapState.busStops) {
like this:
Copy code
@Composable fun MapPanel(mapState: MapState, [...]) {
    GoogleMap() {
        key(mapState.busStops) { for (busStop in mapState.busStops) { Marker([...]) } }
can someone explain me why it's necessary to embed it into key and why recomposition does not trigger if not? Thank you