https://kotlinlang.org logo
#compose
Title
# compose
a

amar_1995

08/21/2020, 2:53 PM
I want to show data in screen after
onCommit
completes. What is the suggested ways to do this ?
a

Adam Powell

08/21/2020, 2:55 PM
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

amar_1995

08/21/2020, 2:58 PM
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

Adam Powell

08/21/2020, 3:01 PM
so this code is requesting the data as part of the
onCommit
side effect and writing to the
savedInstanceState
object when it completes?
a

amar_1995

08/21/2020, 3:01 PM
Yes
a

Adam Powell

08/21/2020, 3:02 PM
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