I want to show data in screen after `onCommit` com...
# compose
a
I want to show data in screen after
onCommit
completes. What is the suggested ways to do this ?
a
Can you give a bit more detail on what you're trying to do?
generally onCommit is used for committing side effects as part of the composition. If your composition itself is changing as a direct result of something changed by an onCommit that can often indicate a code smell.
a
I am working on edit screen. I am making a server request to fetch all the datas. After fetching all the data I will show it to screen. In
onCommit(1) {}
block I am saving that data in local object once.
Local object will be a
savedInstance
a
so this code is requesting the data as part of the
onCommit
side effect and writing to the
savedInstanceState
object when it completes?
a
Yes
a
sounds fine then. If you have a suspend version of your data fetch operation things can be a little cleaner using
launchInComposition {}
instead of
onCommit { onDispose {} }
but other than that the patterns are similar
👍 1
generally you'll want to request the data from some other local object provided to your composable that can perform caching of requests and data
and that object can be responsible for whether or not it needs to perform a network request to satisfy the request