6

I am trying to extend multiple components in LWC js. but it is not working

I want to extend OmniscriptBaseMixin(LightningElement) and NavigationMixin(LightningElement)

import { LightningElement, api, track } from 'lwc';
import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin';
import { NavigationMixin } from 'lightning/navigation';

export default class TestLWC extends OmniscriptBaseMixin(LightningElement), NavigationMixin(LightningElement) {

}
3
  • Not tried it myself, but perhaps using extends OmniscriptBaseMixin(NavigationMixin(LightningElement)) would do it?
    – Phil W
    Apr 8, 2020 at 7:51
  • 1
    @PhilW Yes, that'd be the appropriate syntax.
    – sfdcfox
    Apr 8, 2020 at 8:33
  • @Phil W Thanks..It works.
    – Ajinkyasd
    Apr 8, 2020 at 9:42

2 Answers 2

11

Implementing multiple mixin classes in LWC is handled by nesting them in the extends clause. For your case simply use:

export default class TestLWC extends OmniscriptBaseMixin(NavigationMixin(LightningElement)) 
0

It might be useful to note that you can also use Object.assign() to extend your JS class. I think this is much cleaner and human readable. Here is an in-depth explanation.

1
  • 1
    I would not suggest using this with LWC given the way LWCs are "compiled". Using a non-standard approach is likely to trip you up.
    – Phil W
    Sep 21 at 19:38

You must log in to answer this question.

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