Comments (4)
Thanks for the short test case. I fixed this special case.
Nonetheless I would encourage you to move you export to export const App = () =>
, for most React files there is only one export anyway. Also default export tend can also hide usage of a component when using just a grep search and this kind of pattern can make refactoring/view usage more tedious for IDEs/editors.
from eslint-plugin-react-refresh.
Thanks for the advice.
Unless you see something I am missing, if you export a named function as default and you use this name throughout your codebase, I think all of these downsides disappear: auto-imports and auto-renaming work, and you can find your cubs with a global search. I imagine this could be enforced with a a lint rule. If there is a collision in a file you can write import { default as Bar }
.
I like how my import statements look like when I export types alongside the main thing. It is true that I rarely export companion components alongside a main component but I sometimes do it when it exposes slots. If there are too many of them I can always move them to one or multiple files and use the barrel export pattern so as to not break users.
from eslint-plugin-react-refresh.
The issue with default export and so default import is that you can do import Bar from "../components/Foo.tsx"
and then looking for Foo
with global search will miss this usage. (It will still work with "See usages" but sometime it's quicker to just use grep search)
Also probably that renaming Foo
to Foo2
will keep the usage of Bar intact (at least in JetBrains IDEs)
from eslint-plugin-react-refresh.
Sure but that would be breaking the rule of exporting a named function and using this name throughout your codebase. Moreover, you can also rename a named import. Then, global search would not work and re-factoring the original function would not change the local name either. The 2 systems really behave exactly the same.
I would insist on the syntax { default as Bar }
in case of renaming though, because otherwise you could miss that something is being renamed.
Actually, the more I talk about it the more I want to write that lint rule.
Thanks again.
from eslint-plugin-react-refresh.
Related Issues (20)
- Throwing error for typescript type exports. HOT 2
- Correct use with Context API and Vite - docs missing? HOT 2
- Consider not warning on `export *` when re-exported file is passing HOT 5
- Lazy Loading react component get some warning HOT 14
- Capitalized non-function not triggering rule HOT 2
- Possible false-positive with memo default export HOT 4
- Please add better description what it does HOT 2
- Add option for allowList of export names HOT 3
- False positives in v0.4.4 HOT 12
- How to use in flat config HOT 1
- Support for styled components HOT 1
- Warn exports instead of components when using only components HOT 3
- How to configure your plugin to work with a Vite+React project? HOT 2
- Possible false positive/negative HOT 1
- Allow constant exports doesn't work with objects. HOT 3
- Question about potential problems with barrel files HOT 1
- Bug: ts declaration types are not shipped with the package HOT 8
- feature request: Allow lazy loading HOT 4
- Modern eslint.config.js support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-react-refresh.