Is there any way to pass data from view in lower t...
# compose
s
Is there any way to pass data from view in lower to upper compositional hierarchy e.g we can pass data down through the Composition implicitly using compositionalLocal but can we pass data UP using compositionalLocal or other ? what you suggest.
k
Why would a lower level view own a piece of data to begin with
Also composition locals are very much not for passing data down the tree
s
working on a project that changes view components depending on the data in other view
k
Right, but in compose and in reactive frameworks in general, views don’t own data
s
So best way is to use view model I think ?
k
Yes. Data goes down, events bubble up. The place that owns the data is also responsible for updating that data based on these events. And then Compose takes care of updating the parts of the tree that should be updated based on whatever changed in the data.
💯 4
s
In my project we already have view model for each screen
k
So if place A in your app can change the data X, it doesn't change it directly. It bubbles up the change with whatever callback you push down to it, and then that change gets propagated to place B in your app that shows X in the UI.
s
correct but that A is the one level down from B where need to read that data
k
Data ownership and modification is at the root level, not in A and not in B
👀 1
👆 2
👆🏾 1
👍 1