0

When we have aura:method to make call from parent to child, child to parent component with arguments, why do we need component event?

2

As the documentation says:

Use aura:method to communicate down the containment hierarchy. For example, a parent component calls an aura:method on a child component that it contains.

To communicate up the containment hierarchy, fire a component event in the child component and handle it in the parent component.

Using aura:method to communicate to the parent means that multiple listeners are not possible (adding a new listener would "bump" the old listener off without warning). Using aura:method to communicate downwards means that the parent must notify the child of changes, as opposed to using an aura:valueChange event, which means the parent can simply set an attribute and as many child components as necessary are notified automatically.

In other words, it causes undue complications that could be avoided by using component or application events. That's not to say you can't use aura:method, but you should consider it a last resort after using events. The only time when aura:method is really useful is when the child component wants to return a value. Service components are an example of this design. While relatively rare, there are times when aura:method is appropriate. However, you should get used to using components as the preferred method of communication.

| improve this answer | |
  • Thanks for the documentation link and the explanation, that make sense. Cheers! – jks Jul 28 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.