https://kotlinlang.org logo
#compose
Title
# compose
s

stantronic

12/12/2023, 2:31 PM
Hi folks. Is there any recommended way to change multiple mutableState variables in one transaction? the second variable i change doesn't seem to cause a re-render
👀 1
f

Filip Wiesner

12/12/2023, 2:44 PM
way to change multiple mutableState variables in one transaction
This should work:
Copy code
Snapshot.withMutableSnapshot {  }
But that the second variable not causing re-rendering might be a different problem 🤔
☝🏻 1
v

vide

12/12/2023, 2:45 PM
if you're running on the main thread you shouldn't need to use withMutableSnapshot
👆 1
👆🏻 1
👆🏾 1
z

Zach Klippenstein (he/him) [MOD]

12/12/2023, 4:18 PM
Yep if you’re changing it on the main thread and something isn’t invalidating like you expect, using an explicit snapshot probably won’t help since the two states are probably read in separate invalidation scopes, which will still invalidate independently regardless of which snapshot application does so.
s

stantronic

12/12/2023, 5:42 PM
Turns out it was a silly coding error on my part 🤦 wasn't reading my own code carefully enough - i was never passing the altered variable into the component. Now all works as expected. Thanks anyway
👍🏻 1
👍🏼 1
👍🏾 1