0

I'm going through some training videos on Pluralsight, so I'm sure to pick this up. But I'm also doing paid work (on the merit of 10 years of Rails experience). This came up in React, where import Link from 'react-router-dom' only works as import { Link } from 'react-router'dom. Plus, I like checking things right on SO. Beg pardon : )

tidelake
  • 561
  • 1
  • 7
  • 21
  • 4
    because in react-router-dom nothing is exported default, in import statements if we want to import particular function or class we have to use { } braces and pass names we want to import and if we want to import which is exported default by the file then we use import AnyName – Abhay Sehgal Aug 14 '18 at 12:44

1 Answers1

1

It's the difference between the named and default import:

import { Link } from 'react-router-dom'; // import the export named Link
import Link from 'react-router-dom'; // import the default export

To illuminate a little further, if you take a look at the file which handles the exports from react-router-dom, you'll see that there are a lot of named exports, but no default. If there were a default, then:

import Link from 'react-router-dom';

Would import that default export and name it Link

OliverRadini
  • 5,157
  • 13
  • 37