Skip to content

Instantly share code, notes, and snippets.

@ryanwilsonperkin
Created January 27, 2021 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwilsonperkin/f7ab60ecbc54c3406941325d2db9f177 to your computer and use it in GitHub Desktop.
Save ryanwilsonperkin/f7ab60ecbc54c3406941325d2db9f177 to your computer and use it in GitHub Desktop.
Comparison of different import/re-export types
export default function a() {
return "a";
}
export function b() {
return "b";
}
export function c() {
return "c"
}
// Comparison of different ways of importing and "re-exporting" values from example.js
// Import the "default" value and reuse it's intended name
import {default as a} from 'example';
// Shortcut version of the same thing
import a from 'example';
// Import the "default" value and give it a new name
import {default as a2} from 'example';
// Shortcut version of the same thing
import a2 from 'example';
// Import the named values
import {b, c} from 'example';
// Or just one of them
import {b} from 'example';
// Or just one of them, and rename it in the process
import {b as b2} from 'example';
// Or all of them, stored in an object
import * as stuff from 'example'; // stuff === {b: b, c: c}
// Export the default value
import a from 'example';
export default a;
// Shortcut version of the same thing
export {default} from 'example';
// Or convert it from a default to a named export in the process
export {default as a2} from 'example';
// Export a named value
import {b} from 'example';
export {b};
// Shortcut version of the same thing
export {b} from 'example';
// Works with multiple values too
export {b,c} from 'example';
// Export _all_ the named values
// Note: does _not_ export the default value, so "a" would not get exported
export * from 'example'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment