whats the best way to handle API interactions ? Lets say a set of screens need access to some report data from the API, where and when should the API call be made and how should the data be stored and accessible for all those screens ?
p
Pablichjenkov
02/23/2024, 8:19 PM
Encapsulate them in a navgraph and have a ViewModel with the UseCases scoped to this graph.
u
0xf1f1
02/23/2024, 8:31 PM
thanks, do you know of any example github repos or code I could look at to get a better idea ?
p
Pablichjenkov
02/23/2024, 8:34 PM
Honestly no, I do it all the time but in companies closed source. Now, there is a lot of guidance on how to do this. Even the official documentation.
Pablichjenkov
02/23/2024, 8:37 PM
Or look into stack overflow, I have seen this answered before. As simple as binding the SharedViewModel to the graph, and access it from the children NavBackstackEntries.
z
Zach Klippenstein (he/him) [MOD]
02/23/2024, 8:51 PM
This is a general architecture question - nothing compose-specific here, compose is probably just your view layer.