Search code examples
eventspropagationlitho

Is there a way to easily propagate a Litho event from a child to the root parent?


Is it possible to propagate an event from an nth-child to the root parent?

I have been looking out for a good guide that does not involve declaring the event at every node to the root of the tree. My ultimate objective is to expose and event to outside litho and on to Android Kotlin/Java.

I'm seeing this in Litho Events guide but I'm a bit confused as to what this means. Does this mean it can't be done? Or does this mean passing data to sibling can't be done?

enter image description here


Solution

  • You have the option of using @TreeProps which expose a prop to the entire subtree for a component. We generally don't recommend this approach because it can make the dependencies of your Component hard to reason about -- for example if you want to re-use that Component in another tree, it's not clear from the creator of that component that there's a contract that the Component must be hosted in a subtree that defines that specific @TreeProp.

    The warning you screenshot is not really correct, I will work on editing it or removing it.