Bruce Mu Bruce Mu - 1 month ago 6
React JSX Question

When export a module. Should we asign the value to a const variable? Is it a good practice?

Any reason that someone exports a const variable instead of directly export it?

export const abc = function Home(props) {
return (
<div>
<Template {...props} />
</div>
);
}


usually, I will directly export like this:

export function Home(props) {
return (
<div>
<Template {...props} />
</div>
);
}


What are the differences?

Answer

The difference is you're exporting Home as abc in the first case.

I would prefer the second way unless I need to export my function with different name. This is because, when you assign something to a variable, a small bit of memory is reserved for that variable, in this case it's abc. And, this becomes an useless variable if you're not reusing it anywhere. So, going with the second option is a good practice.

Hope this helps!