MyComponent/index.js? or ALWAYS have file name reflect default export?
See original GitHub issueRegarding this issue: https://github.com/airbnb/javascript/issues/949
I find it difficult to work in RubyMine/Webstorm with tons of files named index.js
:
- Have to remember to hit a
/
after typing the name and autocomplete is not great - Search results harder to read.
I’d like to suggest the following convention:
- Create the file as
components/MyComponent/MyComponent.js
; - Create an “index” file in that directory with one line:
export { default } from
./MyComponent.js` - Do the import as:
import MyComponent from 'components/MyComponent';
(using the default for the directory.
I believe this may give the best of both worlds in that
- The files are named per the default export.
- Easier file navigation in most editors.
- Avoid having multiple editor tabs open that say
index.js
. - Still have the concise import statement for the main file in a directory.
The cost is only to add the index.js
file in each directory with a default component.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
Why and when to use default export over named exports in ...
One can have only one default export per file. When we import we have to specify a name and import like: // import...
Read more >Use Named Exports over Default Exports in JavaScript
A default export can only export a single object, function, or variable and curly braces are omitted when importing in various files. export ......
Read more >Named Export vs Default Export in ES6 | by Alankar Anand
ES6 provides two ways to export a module from a file: named export and default export. Named Export: (export). With named exports, one...
Read more >nbdkit-exportname-filter - adjust export names between client ...
When the client requests the default export name ( "" ), request the export NAME from the underlying plugin instead of relying on...
Read more >Suggested expansion of the "Default export names and file ...
In JavaScript, there is the code smell rule “Default export names and file names should match”. This is a good rule, but a...
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
FWIW I removed my comments because I had the context of the issue wrong methinks.
For those who will bump into this issue in the future: this pattern works fine in IntelliJ-based IDEs.
import boo from 'foo'
will resolve into foo/index.js if there’s such file.