2

What is the difference between:

import App from '../components/App';

and

var App = require('../components/App');

both are used to get components but it is not solving my query asked here: Uncaught Error: Minified React error #130

Syed Ali Taqi
  • 4,898
  • 3
  • 34
  • 44
vinayak shahdeo
  • 1,348
  • 2
  • 11
  • 21

3 Answers3

2

require is used in NodeJS for specifying modules that are needed in your script. For further info, please have a look here. On the other hand, import is a statement introduced in ES6 that is used to import bindings which are exported by another module., as it stated here.

Christos
  • 53,228
  • 8
  • 76
  • 108
0

import/export is one of the ES6 feauture which is used to import/export modules/components. Eg: You can do a named/default export of the React Component. Similarly, you can import them.

export default App

Though most of the web browsers won't understand ES6, Babel or any of the other tool is used for transpilation. Under the hood, these statements are converted to require() by default which uses common.js in node environment.

Vasuki Dileep
  • 573
  • 4
  • 10
0

import/export is one of the ES6 features, you won't see the advantage by just importing the default export. for example you can export other components...etc like this

  export default MainComponent;
  export {OtherComponent}

and you can import them using ES6:

  import MainComponent, {OtherComponent} from '../components/App';

you can do this use ES5 for sure but this is faster...

mohammedgqudah
  • 568
  • 4
  • 15