Skip to content

Instantly share code, notes, and snippets.

@amadeus amadeus/import-export.js
Last active Sep 30, 2019

Embed
What would you like to do?
// Default export
// Export from file.js
const ExampleSomething = {};
export default ExampleSomething;
// import from another.js
import ExampleSomething from './file.js';
// Named Exports
// Export from file.js
export const Another = {};
export const Diff = {};
// import from another.js
import {Another, Diff} from './file.js';
// You can have as many named exports as you want in a file, you can only have
// 1 default export. You can have 1 default export, and multiple named exports
// in the same file as well.
// You can also rename exports when you import them:
// Default export:
import thisCanBeAnythingWhenDefault from './file.js';
// Name export:
import {OriginalName as NewName} from './file.js';
// And finally, you can omit the `.js` file extention when importing a file
import ExampleSomething from './file';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.