Created
November 22, 2023 19:09
-
-
Save shahzadansari/47962aadd7afce3d25d292070cc7e5bc to your computer and use it in GitHub Desktop.
SideEffect Demo (runs every time composable gets recomposed)
This file contains 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
Box(modifier = Modifier.fillMaxSize()) { | |
var count by remember { mutableIntStateOf(0) } | |
StateDependentComposable(count) | |
Button( | |
onClick = { count++ }, | |
content = { Text("Increment") }, | |
modifier = Modifier.align(Alignment.Center) | |
) | |
} | |
@Composable | |
fun StateDependentComposable(count: Int) { | |
SideEffect { | |
Log.d("MyTag:", "Count: $count") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When count changes, composable gets recomposed, resulting it executing the
SideEffect
blockside-effect.mov