[Solved] I have no idea why this happens but my sn...
# compose
l
[Solved] I have no idea why this happens but my snackbar message is triggered twice and only on first run of the screen (not the main screen):
Copy code
val scaffoldState = rememberScaffoldState()
	val scope = rememberCoroutineScope()

	LaunchedEffect(screenState.message) {
		println("screen show message: ${screenState.message}.")
		whenNotNull(screenState.message) { msg ->
			scope.launch { scaffoldState.snackbarHostState.showSnackbar(msg) } // triggered twice
		}
	}

@Stable
class ScreenState {
    var isLoading by mutableStateOf(false)
    var message by mutableStateOf<String?>(null)
    var isFullScreen by mutableStateOf(false)
}

// in viewmodel

    companion object {
        val screenState = ScreenState()
   }
How can the snackbar be triggered twice when LaunchedEffect prevents that and
screenState.message
does not change? EDIT: It only happens when I run the operation that updates screenState.message on screen start like:
Copy code
DisposableEffect(Unit) {
    viewModel.updateMessage()
    onDispose { }
}
Calling the operation from a button doesn't trigger the snackbar twice? EDIT2: Solved: I took some time to note that
LaunchedEffect
provides its own
CoroutineScope
, shame on me.