William
William

Reputation: 974

StencilJS event when child component is updated

If I had something like this in StencilJS.

<mycomponent>
   <my-other-compoent></my-other-compoennt>
</mycomponent>

Would I be able to notify <mycompoent> when any child component is updated?

Upvotes: 2

Views: 2407

Answers (1)

NETGeek
NETGeek

Reputation: 229

You can use @Event to notify your <mycompoent> that something is changed in child component.

For e.g. in your child component create an event like

@Event({ bubbles: true, composed: true }) dataChanged: EventEmitter<boolean>;

and emit this event when something is changed in child component

this.dataChanged.emit(true);

Now in your parent component Listen the event which is emitted by your child For e.g. in your parent component handle the Listenevnt

@Listen('dataChanged',{target: "body"})
    getChangedValue(event: CustomEvent) {
        if (event.detail) {
            let data = event.detail;
            // do something with your data
        }
    }

Upvotes: 5

Related Questions