Computer scienceMobileJetpack ComposeState

Recomposition scope

Analyzing code scopes: Identify recomposition cause

Report a typo

@Composable
fun MyComposable() {
    var counter by remember {
        mutableStateOf(0)
    }
    Box {

        Text(text = "Inside the Box")

        Column {

            Surface {

                CustomText(text = "Recomposed $counter times")
            }

            Button(onClick = { counter++ }) {
                Text(text = "Tap to recompose")
            }
        }

    }
}

Why does Surface scope recompose when we tap the Button in the screen rendered by MyComposable?

Select one option from the list

Create a free account to access the full topic