Skip to content

Instantly share code, notes, and snippets.

@alexilyaev
Last active March 13, 2023 09:10
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 alexilyaev/9d1acebf85e95115e75563b339c549e3 to your computer and use it in GitHub Desktop.
Save alexilyaev/9d1acebf85e95115e75563b339c549e3 to your computer and use it in GitHub Desktop.
Default vs. Named Exports

Default vs. Named Exports

Named Exports Benefits

  • Find Usages/Find References - Easier to search for the export across the project. Less likely to have been renamed or misspelled
  • Easier refactoring of the exported name
  • No need to think of a variable name. Sometimes it's unclear from the file name, especially if it's ../index.js
  • Choosing a named export with IntelliSense autocomplete is faster than writing your own variable. Also prevents spelling mistakes
  • If we only had named exports, it would be easier for new developers to learn how to use it, as there is no extra logical step of choosing which type of import or export to use

Default Export Benefits

  • In case of importing several files with the same name, it's easier to name the import as different variables instead of the verbose { foo as fooBar } of named exports
  • The import looks cleaner

ESLint - import/prefer-default-export

Docs

Why should we turn it off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment