I've been reading/refreshing up on recomposition a...
# compose
c
I've been reading/refreshing up on recomposition and this feels dumb to ask, but why in this example in the 🧵 does updating the value of the mutableState immediately not cause it to recompose infinitely? But after you click the button it recomposes infinitely( which is what I would expect on first composition)
Copy code
@Composable
fun BadComposable() {
    var count by remember { mutableStateOf(0) }

    Button(onClick = { count++ }) {
        Text("Recompose")
    }
    Text("$count")

    count++
}
This is from the examples. I was going to test backwards writing but then realized this didn't make sense why it didn't just recompose immediately upon the
count++
line since
Text
is reading that value?
b
Not a dumb question. I wrote that sample and asked @Chuck Jazdzewski [G] that exact question. It was quite a while ago but by memory it is that the auto-invalidation Compose does, doesn't or can't start until the scope of recomposition exists, and it doesn't exist until that function has completed running or more technically when the generated code the compose compiler is inserting at the bottom of that function to mark the group end, runs
c
Ahhhhh okay. I had come to some sort of conclusion that a function has to run once before it could recompose. I tested it with a SideEffect to confirm the theory. It's good to know I wasn't too far off. This is really useful information, thank you!