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

tjohnn

08/23/2020, 2:44 PM
In what scenario should I use
remember { state }
rather than just
state
? I have tried and my app works thesame way.
a

Adam Powell

08/23/2020, 2:55 PM
that depends on what
state
is. Do you have a more specific example?
t

tjohnn

08/23/2020, 3:00 PM
The state is a mutableStateOf<SomeDataClass>() @Adam Powell
And the state is created from StateFlow.observeAsState()
a

Adam Powell

08/23/2020, 3:09 PM
you do not need to
remember
it yourself then
observeAsState
is responsible for maintaining its persistence guarantees across recomposition
t

tjohnn

08/23/2020, 3:16 PM
Okay thanks. Can you share a resource on remember{}, I’m still confused on it
a

Adam Powell

08/23/2020, 3:25 PM
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

tjohnn

08/24/2020, 5:26 AM
Okay thank you, I think I got it to some extent, would research more