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;
but this does not work. I have to write:
import React from 'react'; export const React = React;
But this is odd. What is the right way to do this?
UPDATED:
Thanks for helps and references. I have solved out my problem with many clues. I'd like to share some common cases for me and the solutions.
import d, {obj} from '...'; export {obj, d}; export {obj as name1, d as name2};
export * from '...'; export * as name1 from '...';
export {a, b as name1} from '...';
export {default} from '...';
export {default as name1} from '...';
With the help of ES6, we can create modules in JavaScript. In a module, there can be classes, functions, variables, and objects as well. To make all these available in another file, we can use export and import. The export and import are the keywords used for exporting and importing one or more members in a module.
In Object Designer, select the object type that you want to export, or select All if you want to export different types of objects to the same file. Select one or more objects that you want to export. To select multiple objects, hold down the Ctrl key when you select objects. On the File menu, choose Export.
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With