How to export imported object in ES6?

后端 未结 5 469
孤城傲影
孤城傲影 2020-12-07 06:55

The use case is simple: I just want to export an object with the name just as it was imported.

for example:

import React from \'react\';
export React         


        
5条回答
  •  一个人的身影
    2020-12-07 07:25

    I often do the following in index.js files that compose several files:

    export {default as SomeClass} from './SomeClass';
    export {someFunction} from './utils';
    export {default as React} from 'react';
    

    This blog entry provides some nice additional examples.

    Important note

    You should be aware this eslint-rule when accessing these exported imports. Basically, in another file, you shouldn't:

    import SomeClassModule from 'SomeClass/index.js';
    SomeClassModule.someFunction(); // Oops, error
    

    You should do this:

    import SomeClassModule, {someFunction} from 'SomeClass/index.js';
    someFunction(); // Ok
    

提交回复
热议问题