Skip to content

Instantly share code, notes, and snippets.

@PhilipDukhov
Created December 1, 2023 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhilipDukhov/38d17370e5156b6a6eac31f55e13da3f to your computer and use it in GitHub Desktop.
Save PhilipDukhov/38d17370e5156b6a6eac31f55e13da3f to your computer and use it in GitHub Desktop.
@Composable
fun SaveableLaunchedEffect(
key1: Any?,
block: suspend CoroutineScope.() -> Unit,
) {
var launched by rememberSaveable(key1) {
mutableStateOf(false)
}
if (!launched) {
LaunchedEffect(key1) {
block()
launched = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment