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
Francesc
05/25/2023, 6:07 PM
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
Alex Vanyo
05/25/2023, 6:20 PM
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▾
Alex Vanyo
05/25/2023, 6:23 PM
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.