Communicating with parent components #468
-
According to docs, child components are not to use ComponentContext's of their parents. So something like this is wrong: class MyComponentImpl(
componentContext: ComponentContext,
rootContext: ComponentContext,
) : MyComponent, ComponentContext by componentContext {
... = rootContext
.instanceKeeper
.getOrCreate(... So what is the right way of creating a communication between parents and their children? For example I want to store some configuration at the root level, so root's children (and children of the children) can use and modify it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you need to push a component then deliver it's result to the previous component, (like startActivityForResult in Android), then please see the docs. In general, you can pass callbacks from parent components to children, so that you can call a callback from the child component and act accordingly in the parent. If you are fine with having shared classes between child components (e.g.. coupling child components with a shared |
Beta Was this translation helpful? Give feedback.
If you need to push a component then deliver it's result to the previous component, (like startActivityForResult in Android), then please see the docs.
In general, you can pass callbacks from parent components to children, so that you can call a callback from the child component and act accordingly in the parent.
If you are fine with having shared classes between child components (e.g.. coupling child components with a shared
InstanceKeeper.Instance
), then you can scope that instance in the parent component and pass it via constructor to child components.