It depends on how they are related. A parent passes data down to a child through public properties decorated with api, and can call the child's public methods. A child talks to its parent by dispatching a custom event. Components with no direct relationship, including those on other parts of the page or in Aura and Visualforce, use Lightning Message Service. Keep data flowing down and events flowing up.
Why interviewers ask this
Component communication is where LWC code either stays clean or turns into a tangle of tightly coupled pieces. The interviewer wants the standard pattern for each relationship, parent to child, child to parent and unrelated components, plus an understanding of one way data flow. Knowing details such as event bubbling and composed settings, and that a child should not change properties passed down to it, shows real component experience.
How to structure your answer
- Cover parent to child with public properties and methods.
- Cover child to parent with custom events.
- Cover unrelated components with Lightning Message Service.
- State the design principles that keep it maintainable.
Example answer
I pick the mechanism by how the components are related. Parent to child is the simple case: the child exposes public properties with the api decorator, and the parent sets them in its template. If the parent needs to trigger something, like resetting a form, the child can expose a public method. Child to parent goes the other way, through events. The child dispatches a custom event with a detail payload, and the parent listens for it in markup. I keep events non bubbling by default and only set bubbles or composed when there is a clear reason, because events that travel through the whole DOM get hard to trace. For components with no direct relationship, say a list on one side of a record page and a detail panel on the other, I use Lightning Message Service with a message channel, which also works with Aura and Visualforce. The rule I follow is data down, events up. A child never modifies a property it received, because the parent owns it; it fires an event and lets the parent decide. That keeps components reusable.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What is the difference between bubbles and composed on a custom event?
- How would you share state between three sibling components?
- Why should a child not change a property passed down from its parent?
Related salesforce developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions