Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Why is dispatch event from lwc to another lwc that is not in the same DOM tree?

Asked by Darsh K May 5, 2023 847 views 1 answer
Share

About this question

I have a lwc that dispatches an event to be received by another lwc that's not in the same DOM tree.


This is my child lwc block of code:

this.dispatchEvent(new CustomEvent('newfilesuccess'));
And this is my listener lwc (not parent):
constructor(){
  super();
  this.addEventListener('newfilesuccess', this.handleFileSuccess);
}
handleFileSuccess = () => {
  console.log('success!');
}

But I can't manage to handle communication between both lwcs. How can I achieve this?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.