export default or...
Okay so this is pretty subtle but confusing. I've once Heard that for example
is considered bad practice. Why? If so how should I name my components to not bother about it ever again?
2 Replies
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 useIts 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