web-componentstenciljsstencil-component

Stencil.js - Listen to class attribute changes on host element


How do I listen to changes to the class attribute on the host element?


Solution

  • There's an easy way to do it, but that might not be appropriate in all situations.

    Simply add 'class' as a @Prop and a @Watch:

    @Prop() class: string;
    @Watch('class') handleClassChange(class: string) {
        console.log(class);
    }