While testing my code, I got confused about Recomposition.
If I have a code like below, then what happens to
value
?
Copy code
var value = false
SomeComposable { item -> // content block
if(item) value = true
// etc.
}
SomeComposable internally runs for loop. Will it run like normal for loop? Will
content block
recompose by itself, making
value
inconsistent?
a
Adam Powell
03/11/2022, 4:50 PM
yes, code with this shape has those problems and it's best to avoid using things like accumulator variables that are mutated by child composables
l
lhwdev
03/11/2022, 4:52 PM
But I thought Composables should run just like normal functions. It would be too burdening to expect such a thing like this..
So, how can I workaround them? I cannot afford modifing
SomeComposable
.
a
Adam Powell
03/11/2022, 4:59 PM
don't mutate
value
during child composition, since child composition can both skip and restart