Jetpack Compose Tutorial #11: Side Effects — LaunchedEffect and Friends
Compose has one rule: Composable functions should be pure. They take state in and produce UI out. No database calls. No API requests. No timers. No logging. But real apps need those things. You need to start a timer when a screen opens. You need to load data when an ID changes. You need to clean up a listener when a screen closes. That is what side effects are for. They let you safely run “impure” code inside Compose. ...