mertceyhan
06/08/2022, 2:52 PMvar foo = rememberSaveable { false }
Csaba Szugyiczki
06/08/2022, 2:57 PMCsaba Szugyiczki
06/08/2022, 2:58 PMvar foo by rememberSaveable { mutableStateOf(false) }
mertceyhan
06/08/2022, 3:02 PMvar foo = rememberSaveable { false }
LaunchedEffect(Unit) {
if (!foo) {
foo = true
}
}
Csaba Szugyiczki
06/08/2022, 3:09 PMCsaba Szugyiczki
06/08/2022, 3:10 PMCsaba Szugyiczki
06/08/2022, 3:11 PMCsaba Szugyiczki
06/08/2022, 3:12 PMmertceyhan
06/08/2022, 3:16 PMfoo = true
doesn’t change the saved value, right? It makes sense, looks like I should use mutableStateOf() even if I don’t need it. It is easy solution.Ian Lake
06/08/2022, 3:30 PMmutableStateOf()
creates a MutableState
object - a recomposition aware wrapper around a set
and get
. While you may not need the recomposition aware part, what rememberSaveable
is capturing is that wrapper object - that's why when the autoSaver calls get
, it gets the latest value you've setIan Lake
06/08/2022, 3:31 PMmertceyhan
06/08/2022, 4:02 PMmutableStateOf()
even if I don’t need it or suggest creating a holder for this?Ian Lake
06/08/2022, 4:04 PMmutableStateOf()
, then if your requirements change and you do need the recomposition part, you'll get that for free