In what scenario should I use `remember { state }`...
# compose
t
In what scenario should I use
remember { state }
rather than just
state
? I have tried and my app works thesame way.
a
that depends on what
state
is. Do you have a more specific example?
t
The state is a mutableStateOf<SomeDataClass>() @Adam Powell
And the state is created from StateFlow.observeAsState()
a
you do not need to
remember
it yourself then
observeAsState
is responsible for maintaining its persistence guarantees across recomposition
t
Okay thanks. Can you share a resource on remember{}, I’m still confused on it
a
I'm looking around to see what we have published, the kdocs on remember itself are kind of thin at the moment
a way to think about it is that it creates an instance field for a composable
generally speaking you should
remember
things you create and want to persist across recompositions, and count on other composable functions to do the same
t
Okay thank you, I think I got it to some extent, would research more