Skip to content

Instantly share code, notes, and snippets.

@amadeus
Last active September 30, 2019 16:32
Show Gist options
  • Save amadeus/8bce5e0acdf34c6798cf8ebd4c858f5c to your computer and use it in GitHub Desktop.
Save amadeus/8bce5e0acdf34c6798cf8ebd4c858f5c to your computer and use it in GitHub Desktop.
// 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