Last active
December 6, 2023 11:24
-
-
Save gab-stargazer/45bef322a773206299a13c2b6886de1a to your computer and use it in GitHub Desktop.
Handle Flow On LaunchedEffect with Jetpack Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
inline fun <reified T> Flow<T>.CollectInLaunchEffect( | |
key: Any, | |
noinline block: suspend (T) -> Unit | |
) { | |
val lifeCycle = LocalLifecycleOwner.current.lifecycle | |
LaunchedEffect(key1 = key) { | |
lifeCycle.repeatOnLifecycle(Lifecycle.State.STARTED) { | |
this@CollectInLaunchEffect.collectLatest(block) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment