Open rglover opened 1 year ago
This would work quite well now if the component has an id
set. Just look in the tree for that ID and get its instance. Should return as an array in case there are multiple instances (i.e., const children = instance.children.get('shared_id')
).
Not sure if this would work but I think it could. If you're building a nested UI, it can be a chore to pass around functions via props. It works, but it's clunky. Ideally, a parent could "call" a child component it renders and access its instance.
The parts are there to do it (everything is just a tree in memory), but a helper function to "get" a child would be great. For example:
Here, we'd get a direct reference to some value
state.cart
on the child. Thesome_id_set_by_child
could be an additional component option that developers could add optionally. If there are multiple instances,instance.children.get()
could return an array of all instances matching thatid
.