Export multiple classes in ES6 modules

前端 未结 6 839
鱼传尺愫
鱼传尺愫 2020-11-28 18:42

I\'m trying to create a module that exports multiple ES6 classes. Let\'s say I have the following directory structure:

my/
└── module/
    ├── Foo.js
    ├──         


        
6条回答
  •  情话喂你
    2020-11-28 19:01

    For multiple classes in the same js file, extending Component from @wordpress/element, you can do that :

    // classes.js
    import { Component } from '@wordpress/element';
    
    const Class1 = class extends Component {
    }
    
    const Class2 = class extends Component {
    }
    
    export { Class1, Class2 }
    

    And import them in another js file :

    import { Class1, Class2 } from './classes';
    

提交回复
热议问题