{ // MainUiModel val uiModel by viewModel.name.collectAsState() // バックグラウンドでStateFlow が更新されてもrecomposition を発生させない val uiModel by viewModel.name.collectAsStateWithLifecycle() }
name: String) class MainViewModel : ViewModel() { val uiModel: LiveData<MainUiModel> field = MutableLiveData<MainUiModel>() val uiModel = field.asStateFlow() field = MutableStateFlow(MainUiModel("")) val uiModel: StateFlow<_> field = MutableStateFlow(MainUiModel("")) }