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

Ian Sikes

11/12/2020, 11:09 PM
hey y'all 👋 I have a question about managing state in Jetpack Compose. Is there a way to perform some "cleanup" on a `remember`'d value before it is recomputed? I'm coming from React land where this is sort of thing is handled by
useEffect
. For example:
Copy code
val (session, setSession) = remember(sessionId) {
    mutableStateOf(Session(sessionId))
}
When the
sessionId
changes, a new
Session
is created. But I need to call
session.close()
beforehand. I can probably think of some hacky way to handle this but I'm trying to figure out what the "correct" Compose way is
d

Dominaezzz

11/12/2020, 11:10 PM
DisposableEffect
might be what you're looking for.
i

Ian Sikes

11/12/2020, 11:15 PM
oh this looks perfect, thank you!