catalinghita8 / android-compose-mvvm-foodies

Android sample app following best practices: Kotlin, Compose, Coroutines and Flow, Hilt, JetPack Navigation, ViewModel, MVVM, Retrofit, Coil
476 stars 89 forks source link

hi,please tell me this #14

Open yuexunshi opened 2 years ago

yuexunshi commented 2 years ago

BaseViewModel: private val _viewState: MutableState = mutableStateOf(initialState) val viewState: State = _viewState

@Composable private fun FoodApp() { val viewModel: FoodCategoriesViewModel = viewModel() val state = viewModel.viewState.value

Any changes to value will schedule recomposition of any composable functions that read value. In the case of ExpandingCard, whenever expanded changes, it causes ExpandingCard to be recomposed.

here dont hava remember,why it can to be recomposed?

i think it is : val state by remember{ viewModel.viewState.value }

but no remember,it can be recomposed.