0

Changing some files from the old way to the newer way (ES6) for import statements. I have a statement like this that has a 'get' in it so it gets the whole JSON file that is at somefolder/somefolder/filename.

let variable = require('somefolder/somefolder').get('filename'); 

I want to change it to something like this:

import {Alert} from 'react-bootstrap';

or

import React from 'react';

Clarification that makes it a non-duplicate question. I want to use the import statement and the ".get" in one line of code (without functions like the previous solution) at the top of the file.

Jay
  • 127
  • 3
  • 10
  • @bergi - this is not a duplicate question. The question you reference does not have the .get on the end which does affect the syntax of the import statement. It doesn't compile. Please unmark it. Thanks – Jay Jun 07 '16 at 15:40
  • 2
    Whether you are invoking a method on the required module (`….get(something)`) or trying to call the required module itself (`…(something)`) doesn't really make a difference here, the takeaway is that you need to split it in two separate statements when using `import` syntax. There is no oneliner solution. – Bergi Jun 07 '16 at 15:44
  • That is what I needed - splitting it into two. Which I don't want to do. If that is the only way, then I will leave it like it is ES5 and below. – Jay Jun 07 '16 at 15:46
  • 2
    *"If that is the only way"* It is. – Felix Kling Jun 07 '16 at 15:47
  • You might also want to have a look at [ES6 - Convert from 'require' to 'import'](http://stackoverflow.com/q/30898686/1048572) (which has `.get` but no call). There's really nothing wrong with splitting it into two lines. Embrace ES6 :-) – Bergi Jun 07 '16 at 15:48
  • Thanks all. Been a big help. – Jay Jun 07 '16 at 15:49
  • Think about `import` statements as "directives" that tell the interpreter which dependencies to load, not as code that is actually executed. – Felix Kling Jun 07 '16 at 15:51

0 Answers0