How can I use the module as extends class
viniciusbitt opened this issue · comments
I have a doubt, there is a library (createjs-module) that I wanted to use as extends of a class, but I believe that it is not possible to use import directly in the extends of the class
Example:
const createjs = import("createjs-module").then(...);
export default class MyClass extends createjs.Sprite {
}
I'm using next-js
You will have to export a Promise, like this:
export default import("createjs-module").then((createjs) => {
return class extends createjs.Sprite {
};
});
Or as an alternative, you can use top level await
:
const createjs = await import("createjs-module");
export default class MyClass extends createjs.Sprite {
}
However, that will block the module loading until the Promise is finished, and it is worse performance than using import { Sprite } from "createjs-module";