Search code examples
typescriptautodesk-forgeautodesk-viewer

Autodesk forge viewer, react+typescript Extensions


I am just starting with React and Typescript and I have a question, very basic may be... In the viewer documentation, extensions are defined as classes, is it possible to transform that class into a typescript function? does it make any sense? for example this simple class extension:

export class MyExtension extends Autodesk.Viewing.Extension {
   load() {
     console.log('MyExtension has been loaded');
     return true;
   }
 
   unload() {
     console.log('MyExtension has been unloaded');
     return true;
   }
 
   static register() {
     Autodesk.Viewing.theExtensionManager.registerExtension(
       "MyExtension",
       MyExtension
     );
   }
 };

How should it be as a function? Thanks in advance


Solution

  • I searched for this topic and only found it in context of React Class Components being turned into React Functional Components

    A Viewer extension is not a React component, so not sure this technique could be applied.

    Also, if you look in the source code of the Viewer you'll see that when loading the extension, loadExtensionLocal will try to create a new instance of the extension class. So it seems like the extension needs to be a class.