I have below lwc components hierarchy.Custom events are fired in the Child2 , handle it in Parent , do some modification to the payload and assign it to a @track property (filters) in parent . On click of a button in Child1.cmp , it should always save the values of childfilters. However, childfilters is undefined , though filters is not a undefined. How can I have childfilters in Child1.js same value as filters in Parent.js during button click in Child1.js


    <Child1> childfilters = {filters}



 filters = [];
 // Some code
 filters = SomeValues;


<Child 1>
    <lightning:button onclick = {savefilter}>
 </Child 1>


     console.log('childfilters '+childfilters); // this logs undefined 
  • Can you please post the exact code in Parent.js where you're handing the custom event and assigning new value to filters?
    – Jay Rathod
    Feb 9, 2021 at 12:58

1 Answer 1


Your child should notify the parent when there's a change:

<lightning-input ... onchange={handleFilterChange}>


// Inside child1.js
handleFilterChange(event) {
  this.dispatchEvent(new CustomEvent('filterchange', {
    detail: { childfilter: { /* fill this part out */ } } }

And the parent should handle it:

<c-child1 childfilters={filters} onfilterchange={handleFilterChangeEvent}>


handleFilterChangeEvent(event) {
  this.filters = event.detail.childfilter;

Alternatively, you can set an @api get and set method, then return some sort of backing variable that may have been updated:

@api get filters() {
  return this._filters;
set filters(value) {
  this._filters = value;

Which you then query on-demand:

const filters = this.template.querySelector('c-child1').filters;
// do something here

I wrote a complete working example using generic HTML in this web component.

The demo doesn't build a complete complex object, but you can build as complicated of a detail property as you need.

If you use the get/set method, it is recommended that you validate the input instead of just accepting whatever comes in (as in my example).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .