3 ms·
I think his criticism of that approach is that you end up with a bunch of index.tsx tabs open in your IDE and it can be hard to tell what is what. My approach
by dsmmcken 5y ago
I think his criticism of that approach is that you end up with a bunch of index.tsx tabs open in your IDE and it can be hard to tell what is what.
My approach is similar to his, but is simplified to have one index at the top of the components folder for all the components:
components
index.tsx <- wrapper exports all components
mywidget.tsx
myotherwidget.tsx
mycomplexwidget
mycomplexwidget.tsx
subpart.tsx
Then import is easy, and feels less redundant
import { mywidget, mycomplexwidget } from '@foo/components'
- beaconstudios 5y agoThat issue with too many index.ts files used to be a major issue but nowadays I use VS Code which disambiguates matching filenames with their parent directory. I think I just don't really like using re-exporting index files if I can avoid them, because I don't see much of a positive cost/benefit in most cases. In your example I'd be doing something like this instead: import { mywidget } from '@foo/components/mywidget'; import { mycomplexwidget } from '@foo/components/mycomplexwidget'; I could fish for pseudo-objective arguments for this but honestly I think it's mostly just personal preference!
- deanc 5y ago> That issue with too many index.ts files used to be a major issue but nowadays I use VS Code which disambiguates matching filenames with their parent directory. Any source on that. I'm in vscode right now with several index.tsx files open and no disambiguation in the tabs.
- beaconstudios 5y agohere's a screenshot from my VS Code right now: https://imgur.com/a/kTbBjJP https://imgur.com/a/kTbBjJP it's controlled by the "workbench.editor.labelFormat" setting, but the default will disambiguate when two files share a name.