# compose

Tomas Gordian

12/07/2021, 12:41 PM
What should I use to only observe state inside composable and trigger recomposition, but without caching the state so I can set the same value? 🧵
I have two composables, in the first one I have some buttons that should trigger different animations, which I am doing in the second composition. I want to be able to click on the same button and start the same animation. My current solution is to reset the animation state to default values when the animation is finished, but this causes unnecessary recomposition, is there a better way?
Copy code
fun MainScreen() {
    var animation by remember { mutableStateOf(AnimationWrapper()) }

    Column {
        Card(animation = animation)

        Button(onClick = {
            animation = AnimationWrapper(400, 8)
        }) {
            Text(text = "Button")

fun Card(animation: AnimationWrapper) {
    // make some animations based on animation wrapper

data class AnimationWrapper(val duration: Int = 0, val rotation: Int = 0)