Is there any performance hit, undesired side effects or preferred standard when exporting an anonymous React component versus a named component?
anonymous component export
import React from 'react';
export default ({ title }) => <div>{title}</div>;
named component export
import React from 'react';
const MyComponent = ({ title }) => <div>{title}</div>;
export default MyComponent;
Named exports are only truly necessary when you are doing non-default exports.
I disagree with the above.
With IntelliSense and/or TypeScript export default MyComponent is preferable because it tells Intellisense and TypeScript more and allows you to automatically import your module using extensions in your IDE. If there is no performance hit then the named export is the superior syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With