DEV Community

Discussion on: What are the differences between the following two methods?

Collapse
 
sargalias profile image
Spyros Argalias

First one is a default export. You can import it in another file with any name you like. For example, foo, bar, anythingYouWant, etc.

Example:

import thisCanBeNamedAnythingYouWant from './path/to/file';
Enter fullscreen mode Exit fullscreen mode

The bottom one is a named export. It's missing the keyword default. You need to import that one with the correct name and with curly braces, like this:

import {router} from './path/to/file';
Enter fullscreen mode Exit fullscreen mode

More information at: developer.mozilla.org/en-US/docs/w...

Collapse
 
shweblee profile image
sh-web-lee

thank u. ok, I got it. So this is why I can't use 'router' in another JS file when I did as same as method 2