export default or...

Okay so this is pretty subtle but confusing. I've once Heard that for example
export default function Home()
export default function Home()
is considered bad practice. Why? If so how should I name my components to not bother about it ever again?
2 Replies
John
John2y ago
I think its more about the whole module thingy then React component. So the problem with default is that when you import things like import THREE from 'threejs' it imports WHOLE library, the functions that you might not need. When you import only import {someshit} from 'somelib' you only use what you use
shaaah
shaaah2y ago
Its considered bad practice because, lets say you have to use this in 3 different files you could end up importing it as import Home from "./Home" import HomE from "./Home" import Homee from "./Home" As you can see, you can litreally make a typo and you wouldnt know it, now if you want to do a global search on Home, you'll only find one because of all the other typo So its always better to export it as export function Home() and import it as import {Home} from "./Home" This way you cant make a typo
Want results from more Discord servers?
Add your server