Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: Anonymous export default vs. Named export default

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;
like image 453
proph3t Avatar asked Oct 28 '25 07:10

proph3t


1 Answers

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.

like image 185
tshm001 Avatar answered Oct 30 '25 23:10

tshm001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!