camiloparradev
09/16/2022, 10:33 PM// 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?Mustafa Ozhan
09/16/2022, 11:04 PMfactory then?
// Module
factory { MyViewModel() }