Giter Club home page Giter Club logo

Comments (7)

ArnaudBarre avatar ArnaudBarre commented on September 22, 2024 4

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.

ArnaudBarre avatar ArnaudBarre commented on September 22, 2024 1

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.

ArnaudBarre avatar ArnaudBarre commented on September 22, 2024 1

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.

hichemfantar avatar hichemfantar commented on September 22, 2024 1

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.

hichemfantar avatar hichemfantar commented on September 22, 2024

Understandable, thanks for the clarification.

from eslint-plugin-react-refresh.

hichemfantar avatar hichemfantar commented on September 22, 2024

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:
image
image

from eslint-plugin-react-refresh.

hichemfantar avatar hichemfantar commented on September 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.