Export-ing conventions
See original GitHub issueAirbnb style guides [10] do not define any specific export
style, other than:
10.6 In modules with a single export, prefer default export over named export.
Which one is the preferred style in the following cases (feel free to suggest better ones):
Single export
- Inline export
export default foo = () => { ... }
- Separate export (after definition)
const foo = () => { ... };
export default foo;
const other = () => { ... };
- Separate export (at the end of file)
const foo = () => { ... };
const boo = () => { ... };
export default foo;
Multiple exports
- Inline exports
export foo = () => { ... }
export boo = () => { ... }
- Separate export (after definition)
const foo = () => { ... }
export foo;
const boo = () => { ... }
export boo;
- Separate export (at the end of file)
const foo = () => { ... }
const boo = () => { ... }
export { foo, boo };
- Wrapper export
export const wrapper = {
foo: () => { ... }
boo: () => { ... }
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
Attend An Event
Webinars, local seminars, and national conferences are a great way to connect ... recruited, and led by private and public sector export-oriented groups, ......
Read more >Convention on the Means of Prohibiting and Preventing ...
The States Parties to this Convention recognize that the illicit import, export and transfer of ownership of cultural property is one of the...
Read more >Exporting Corruption 2022: Assessing Enforcement…
Our report assesses foreign bribery enforcement in 43 of the 44 signatories to the OECD Anti-Bribery Convention as well as in China, Hong...
Read more >New International Requirements for the Export and Import ...
What requirements apply, if any, to U.S. exports and imports of plastic scrap and waste not controlled under the Basel Convention (Basel ...
Read more >Exported Designs - Custom Naming Conventions
Exported Designs - Custom Naming Conventions. If your team has a custom naming convention that all design files must follow, Flexitive can help...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Tests should absolutely not only be end to end, its the entire reason smaller functions are considered best practise, because its easier to test a small function than a large function. As for you previous comment, I’m not sure I understand. They don’t have to be exported but can be imported?
In most cases, you should be exporting one conceptual thing from a module. In other words, if you have both “foo” and “boo”, those are two modules and thus should be
export default
ed from two separate files.If you insist on having them in the same file (there are some use cases where this makes sense, but not many), then you should be using multiple named exports.
When exporting one thing, and inline export is nicer because it ensures that you can not change the binding later (ie,
export default function foo() {};
is better thanfunction foo() {} ; export default foo;
)As far as positioning, there will soon be a linter rule in
eslint-plugin-import
that will require that all export statements are grouped together - so I’d recommend grouping them together and putting them at the bottom of the file.