I want to pass data between 4 screens in compose. ...
# compose
c
I want to pass data between 4 screens in compose. What strategies should I use? I have seen options of using SharedViewmodel, CompositionLocal and Room?
j
maybe that question will be more suitable for #android-architecture? Or you aren't targeting Android only?
c
I am building a compose app for android, I am having challenges passing data across different composables. Would you kindly advise?
j
not a Compose expert at all, I answered because I'm interested in the response you'd get
f
it depends on what navigation framework you use. If you opt for the AAC (Android Architecture Components) navigation, then navigation arguments are available in the viewmodel via the
SavedStateHandle
so that would be an option
c
Thank you for the suggestion. Yes, I am using AAC navigation, but have never used
SavedStateHandle
to store data. Let me look into it asI look for more options.
f
any argument that you pass to a composable will automatically be populated into the saved stated handle object that the viewmodel receives, so it does all the wiring for you
you can check the NowInAndroid app for reference
c
Thank you. Let me use this apprroach