https://kotlinlang.org logo
#compose
Title
# compose
m

Marcello Galhardo

01/05/2021, 5:23 PM
What is considered the best way to connect a ViewModel to a Composable? Using a "mutable"
StateFlow
or
LiveData
that is "collected as state" and receive new values directly (e.g.,
onChanged = { vm.stateFlow.value = it }
or creating a "local remembered state" and passing it back only when necessary (e.g.,
onClick = { vm.onClick(myRememberedState.value) }
). 🤔
2
n

nglauber

01/05/2021, 6:07 PM
hi @Marcello Galhardo 👋 In my last presentation I suggested to pass the VM as parameter… Not sure if it’s the “good practice”, but sounds more easy to me at first glance… https://www2.slideshare.net/nglauber/jetpack-compose-a-new-way-to-implement-ui-on-android/62
👍 1
n

Nat Strangerweather

01/05/2021, 6:08 PM
4 Views