https://kotlinlang.org logo
#compose
Title
# compose
c

Chachako

02/24/2021, 7:23 AM
Is there a way to update the variables without directly reorganizing them?
remember { mutableStateOf(...) }
will be reorganized immediately after each
setValue
, but I just want to update the variable, and then manually reorganize and remember this variable at some point. what should I do?
k

Karthick

02/24/2021, 8:45 AM
use can
var value = remember { value }
without mutableState and another variable
var state = remember { stateOf(value) }
for ui. And can change state at some point
1
c

Chachako

02/24/2021, 8:52 AM
I'm very much obliged to you! In the end it should look like this:
Copy code
var stateSize by remember { mutableStateOf(0) }
var size = stateSize

try {
    xxx.forEach {
        size++
    }
} finally {
    state = size
}

Text(text = "last = $stateSize")
a

Adam Powell

02/24/2021, 2:47 PM
This looks a bit suspicious. What is the intent behind this code? This is very close to a pattern that will not behave as you might expect.
2 Views