If we can use a view model, is it considered bad p...
# compose-android
h
If we can use a view model, is it considered bad practice to use
rememberSaveable
instead? For example, is it bad practice to remember the index of the selected tab bar inside a composable function instead of a view model? And if so, are there any boundaries?
f
I don't think so. It all depends on who needs to have access to the information. Storing everything in the viewmodel will make your viewmodel bloated and harder to maintain. There is information that is only pertinent to the composable and, in that case, a
rememberSaveable
or a state holder for somewhat more complex logic is the right approach.
a
If you haven’t seen it, @Manuel Vivo gives a great explanation of the differences between
rememberSaveable
,
ViewModel
,
SavedStateHandle
and persistent storage in

https://www.youtube.com/watch?v=V-s4z7B_Gnc

Each of them has their uses and limitations, it’s definitely not a bad practice to use
rememberSaveable
if you’re also using `ViewModel`s. It isn’t a one-or-the-other issue.
h
Thank you, I will take a look :)