I'm using TextField to get user input and using stateflow to handle the text state/value in viewmodel.
The thing is every time TextField's value changes the HomeContent() function get recomposed.
Layout inspector output image My question is, is it ok that the whole HomeContent() function is getting recomposed just because the TextField value changes or is there a way of avoiding function recomposition?
ViewModel
class MyViewModel() : ViewModel() { private val _nameFlow = MutableStateFlow("") val nameFlow = _nameFlow.asStateFlow() fun updateName(name: String) { _nameFlow.value = name } } MainActivity
class MainActivity : ComponentActivity() { private val myViewModel by viewModels<MyViewModel>() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { AppArchitectureTheme { HelloScreen(myViewModel) } } } } HomeScreen
@Composable fun HelloScreen(viewModel: MyViewModel) { val name = viewModel.nameFlow.collectAsState() HelloContent( provideName = { name.value }, onNameChange = { viewModel.updateName(it) }) } @Composable fun HelloContent( provideName: () -> String, onNameChange: (String) -> Unit ) { Column(modifier = Modifier.padding(16.dp)) { Text( text = "Hello,", modifier = Modifier.padding(bottom = 8.dp), style = MaterialTheme.typography.h5 ) OutlinedTextField( value = provideName(), onValueChange = { onNameChange(it) }, label = { Text("Name") } ) Button( onClick = {} ) { Text(text = "Dummy Button") } } } 
HomeContentis being recomposed, but you have one composable calledHomeScreenand one calledHelloContent. Neither one is calledHomeContent.