is used in Compose Dialog to remember content, but I still can’t understand what describes in kdoc. Could someone please explain it to me. I am grateful.
👀 3
a
Albert Chang
04/29/2021, 7:29 AM
I think the doc is quite easy to understand. Basically it's used to create a value holder which always holds the latest value. If you still don't understand, reading the source of
rememberUpdatedState
may help.
Copy code
@Composable
fun <T> rememberUpdatedState(newValue: T): State<T> = remember {
mutableStateOf(newValue)
}.apply { value = newValue }
Albert Chang
04/29/2021, 7:32 AM
As for the reason why it's used in
Dialog
, I believe it's that the
content
lambda is executed in another
setContent
call, which means that the content will not be correctly updated if recomposition is not explicitly triggered by the