I have one question. how can i handle rember state...
# compose
i
I have one question. how can i handle rember state on bottomnavigation switch. I have a home screen with a composable that has a
Copy code
var isPlayingState by remember { mutableStateOf(false) }
and set it in clickable (Box)
Copy code
isPlayingState = if (player.isPlaying) {
    player.pause()
    false
} else {
    player.play()
    true
}
If i navigate to the second tab and navigate back the value ist false and not the last state i set ?why?
d
it is likely that the declared variable is no longer in composition when you navigate to the other tab. one way to resolve this is to hoist the isPlayingState out of the scaffold of your content
j
Or, depending on how ViewModels are scoped, put the state into the viewModel
i
mhmh
i dont set the value in a viewmodel right now all i do is call a home composable with a player composable and set the remember value and the click event .in my scafold