Hii folks :cmp: :kotlin_emoji: How do you implemen...
# compose
r
Hii folks cmp K How do you implement fetching in an API based on a lazy layout? After reaching section X, perform the fetch, then perform the fetch in another section, and so on. I thought it was a launched effect, but when exiting and re-entering the app, it makes an unnecessary fetch again. It's important to me that it be a testable form without a view model (something like a lambda or flag). Thx u in advance
p
This is the workaround I use: https://gist.github.com/pablichjenkov/21691f49ed386ba92d58a5fb0fef1588 I have asked in different forums and no one has a clear API for this.
r
Thx @Pablichjenkov for the workaround in launched effect, so you recommend use launched effect in lazy layout?
p
What other options do you have for what do you want to achieve? - I personally prefer the compose LifecycleEffects API over LaunchEffet(Unit). But, both alternatives are affected by the fact that the lazy column detach the item/section from the composition when it goes off the screen frame. Then it attaches it back when the section becomes visible again. There is no way to fight that, so basically what I do, is track every time this situation happens, then separate the first time from the subsequent times. So it is easier for one to decide what to do in what case. For your useCase, you will only fetch data remote the first attachment to composition. The subsequent reattachments, you will ignore.