Recomposition in compose - does it go through each...
# compose
r
Recomposition in compose - does it go through each node(composable) in the tree and checks if that nodes needs to be updated or not based on last state from slot table?
1
Copy code
@Composable
fun MainScreen(viewModel:Vm){
  // live-data in vm
  when (viewModel.response.observeAsState().value) {
    //   
  }

  ScreenContent(
    sate = viewModel.emailState.collectAsState().value,
    onValueChanged: viewModel::valueChanged
  )

}

@Composable
fun ScreenContent(
  state:SomeState,
  onValueChanged:(String) -> Unit
){
  TextField(value = state.text, onValueChange = onValueChanged)
}
Why
MainScreen
Composable, is called(recomposed/invalidated) again when
ScreenContent
is changed. I believe only
ScreenContent
should be recomposed in this case.
a
ScreenContent
isn't what's reading the
.value
of the snapshot state objects being invalidated,
MainScreen
is
r
Thanks Adam, i was under the assumption that
re-composition
is based on parameters passed down in the tree hierarchy, and if there is a difference from last state, only that composable will re-compose, not the parent node.
a
a parameter's value is controlled by the caller. For a parameter to change the caller must run to pass a new value
👍 2
r
a parameter's value is controlled by the caller. For a parameter to change the caller must run to pass a new value
also, this article by Zach cleared my doubts related to node invalidation
👍 1