What is the use of component event which we fire and handle in the same component? I mean what is the specific use case for it...like apart from our regular controller actions...

  • 1
    Are you asking about component event or your specific use case? – Tushar Sharma Jul 17 '18 at 5:50
  • Yes, for component event – optimistic_cloud Jul 17 '18 at 10:58

Let's say that there are 2 div boxes. If you hover over the 1st box, then the 2nd one should be greyed out. If you hover over the 2nd box, then the 1st one should be greyed out. On click of any of the boxes, the other one will be completely disabled. For this usecase, you need to fire and handle an event in the same component.

  • I think we can easily do this using action as well. – Tushar Sharma Jul 17 '18 at 6:05

Events are primarily for inter component communication, that is, usually there is more than one component involved. In your case, what if the component is within an aura:iteration? Although it is the same component under the hood, on the page there are multiple instances of the same component so it satisfies 'more than one' logic. Now for a use case, say there is a component that displays a product/item. A page is showing multiple such items. Now when a user selects a product in one category, all other items from the same category must automatically be checked. Remember that each item is the same (programmatically) but a separate (visually) component. So to filter out the products that you want to select conditionally, you could choose to fire and listen to a component event on field change within that one component.

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.