While using view model with jetpack compose, I am trying to update the viewmodel from a button inside the view. I want the state of the composable to be updated from outside it inside the fragment. Below is the gist of what I tried to do. How can I update the composable on an event on a button inside it, however from an action outside of the composable?
Leland Richardson [G]
06/20/2020, 8:58 PM
You are assigning a variable to a new livedata instance instead of mutating the livedata instance itself
If you did that instead, then observing the livedata like you are there would be enough
06/22/2020, 10:09 AM
@Leland Richardson [G] Yes you are right. I am overwriting the existing live data, so it won't be observable from the view. However it's kind of tricky. I have to either observe the live data both inside my Fragment and the Composable; otherwise I have to pass the viewmodel itself to the Composable (which I didn't wanna do, I thought that's too much knowledge for the Composable).