Hello, I want to provide a different instance of a ViewModel into many Composables.
// Module
viewModel { MyViewModel() }
class MyViewModel : ViewModel() {
var feedId: Int by Delegates.notNull()
}
@Composable
fun MyComposable(myViewModel: MyViewModel = getViewModel(), feedId: Int) { // Using myViewModel with a specific feedId }
feeds.forEach {
MyComposable(feedId = it.feedId)
}
So each
MyComposable
can have its own viewModel, but what seems to happen to me is that all
MyComposable
are sharing the same instance of
MyViewModel
. Like
getViewModel()
is always providing the same instance. Am I right? Is there a way to provide different instances for each
MyComposable
?