Skip to content

Instantly share code, notes, and snippets.

@euri16
Created June 7, 2025 16:57
Show Gist options
  • Select an option

  • Save euri16/be39a09f67681bc7168ab00256a336f6 to your computer and use it in GitHub Desktop.

Select an option

Save euri16/be39a09f67681bc7168ab00256a336f6 to your computer and use it in GitHub Desktop.
@Composable
fun <EFFECT> LaunchedUiEffectHandler(
effectFlow: Flow<EFFECT?>,
onEffect: suspend (EFFECT) -> Unit,
onConsumeEffect: () -> Unit,
) {
val effect by effectFlow.collectAsStateWithLifecycle(null)
val currentOnEffect by rememberUpdatedState(onEffect)
val currentOnConsumeEffect by rememberUpdatedState(onConsumeEffect)
LaunchedEffect(effect) {
effect?.let {
currentOnEffect(it)
currentOnConsumeEffect()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment