Created
September 17, 2024 01:11
-
-
Save Farhandroid/8a8577540068bb7637186024393d52a5 to your computer and use it in GitHub Desktop.
RememberCoroutineScope
This file contains hidden or 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 | |
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