is there a way to not reset `remember{}` states an...
# compose
o
is there a way to not reset
remember{}
states and pretty much not reload a screen A, when navigating to another composable B and back press to A, I see that everything is cleared as if A is starting from scratch
a
rememberSaveable
though it depends on what you want to save
i wouldnt store lists of content in there. only small ui related information that is useful
r
I wonder if we should be using
rememberSaveable
here, as it's more suitable for re-creation or process-death. Instead hoist the state all the way up to vm.
a
yeah, exactly
o
thanks for the replies guys! in my compose screen I inject the viewmodel
Copy code
@Composable
fun MyComposable(
    viewModel: MyViewModel = getViewModel(scope = myScope), 
    ...
) {
...
and then I initiate the first call with
Copy code
DisposableEffect(key1 = viewModel) {
    viewModel.doSomething()
    onDispose { }
}
when I go back,
viewModel.doSomething()
is triggered again, is there a way in compose to make this a one time call? or do I also have to store the state in the vm?
even with
DisposableEffect(key1 = null)
it’s always triggered
i
If you want to do something one time, it can't be part of composition at all, it should be done in the ViewModel e.g., in the
init
or a
by lazy