Hi :wave: , I’ve been running into this situation ...
# compose-android
e
Hi 👋 , I’ve been running into this situation and wanted to get your thoughts. On bigger/complex screens, I often deal with multiple API calls and lists. Sometimes I reuse the same UI component (or “sub-screen”) across different parent screens. That component often needs the same data. For example, imagine we have a post list, and each post has comments. This list is used in multiple screens (say, 3 screens), and within this list, there are 7 API calls that need to be handled in the ViewModel. My preference is to keep a 1:1 relationship between a screen and its ViewModel. For these reusable components, I’m thinking about splitting the list and its API handling into a sub-ViewModel or sub-screen, so it’s easier to reuse. I’m not sure if this is a good approach in Jetpack Compose or not. Do you think this is still a good approach for reusability, or is there a better pattern to avoid duplicating ViewModels across screens?
j
What about having the components take a “State” object that you view models expose the state needed to render the reusuable composables?