'Why do the author need to add remember for a variable from viewModel?
The Code A is from the official sample.
In my mind, I needn't to wrap a variable from viewModel because it has more long life cycle.
But why do the author need to add remember for a variable from viewModel ?
Code A
@Composable
fun DetailsScreen(
onErrorLoading: () -> Unit,
modifier: Modifier = Modifier,
viewModel: DetailsViewModel = viewModel()
) {
val cityDetails = remember(viewModel) { viewModel.cityDetails }
...
}
@HiltViewModel
class DetailsViewModel @Inject constructor(
private val destinationsRepository: DestinationsRepository,
savedStateHandle: SavedStateHandle
) : ViewModel() {
...
val cityDetails: Result<ExploreModel>
...
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
