Skip to content

Instantly share code, notes, and snippets.

@Farhandroid
Created September 17, 2024 01:11
Show Gist options
  • Save Farhandroid/8a8577540068bb7637186024393d52a5 to your computer and use it in GitHub Desktop.
Save Farhandroid/8a8577540068bb7637186024393d52a5 to your computer and use it in GitHub Desktop.
RememberCoroutineScope
@Composable
fun InteractiveScreen(snackbarHostState: SnackbarHostState) {
// Remember a CoroutineScope tied to the lifecycle of InteractiveScreen
val scope = rememberCoroutineScope()
Column(Modifier.padding(16.dp)) {
Button(onClick = {
// Launch a coroutine when the button is clicked
scope.launch {
snackbarHostState.showSnackbar("Action triggered!")
}
}) {
Text("Press me")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment