1

I am currently learning react and I have an app using webpack, babel and react. It seems react has two ways of writing it using either required or import. It also seems there is a lot more documentation on using import. How can I change my stack to use the import version?

Jamie
  • 1,909
  • 3
  • 22
  • 47

2 Answers2

4

The import and export statements are an ES6 standard. Right now, your setup is likely using Babel to transpile this into ES5. You can use one or the other, but import/export will soon become the standard, so adopting it is advised.

glhrmv
  • 1,712
  • 1
  • 16
  • 23
Nevosis
  • 1,366
  • 1
  • 16
  • 27
0

import is ES6 (or ES2015) standard. To use it, you need to install and activate the preset in babel.

Follow these steps:

  1. Go to your project folder then type this: npm install --save-dev babel-cli babel-preset-env
  2. Create a file named .babelrc (in case you have not created one) and insert this lines:

    { 'presets': ['env', 'react'] }

I assume you have setup the webpack to work with babel.

Win
  • 2,083
  • 2
  • 11
  • 14