Comments (7)
Yep that's normal because you export an anonymous component which is not recommended because this will not be available in devtools and stack traces.
function InnerCardContainer(props,ref) {
return <div ref={ref}>Hello world!</div>;
}
export const CardContainer = forwardRef(InnerCardContainer);
from eslint-plugin-react-refresh.
Interesting, I never really tested this fact from the React team because for me there is a good reason to name you component and ban default export: https://jamie-wong.com/2013/07/12/grep-test/
from eslint-plugin-react-refresh.
That could be a challenging refactor, but I advice you to move to export const CardContainer
. On top of being simpler to write, it's more align with what I do in other files where I can export a bunch of functions, contants and so on.
The default export add a barrier to export multiple React component in the same file, which I used often when there are 2-3 small components related to each other. (And this avoid the component to be imported in another file with a typo/rename and not being greppable (even if IDE & TS will found it, sometimes that's nice to be able to have confidence in the result of a global search))
from eslint-plugin-react-refresh.
Named exports is definitely more convenient and easier to follow.
I'm currently slowly refactoring default exports to named exports and I'm def noticing improvements.
Thanks for the tips, I'm slowly incorporating them into my current project.
from eslint-plugin-react-refresh.
Understandable, thanks for the clarification.
from eslint-plugin-react-refresh.
One more thing @ArnaudBarre , you said the component will not be available in devtools and stack traces yet the component appears normally in the devtools and in the profiler.
examples below:
from eslint-plugin-react-refresh.
Thanks for the article, that was a good read.
I ended up using this syntax to avoid renaming the function.
const CardContainer = forwardRef(function CardContainer(props,ref) {
return <div ref={ref}>Hello world!</div>;
})
export default CardContainer;
from eslint-plugin-react-refresh.
Related Issues (20)
- 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 6
- 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
- False positive on `export { X as default }` HOT 4
- Modern eslint.config.js support HOT 3
- False positive for negative number with allowConstantExport HOT 1
- Possible false-positive with memo default export HOT 7
- Type exports should be ignored HOT 2
- false positive for memoizing generic component? HOT 2
- How can I prevent eslint error in Next.js's getServerSideProps? HOT 2
- Key "plugins": Key "react-refresh": Expected an object. HOT 5
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.