Reaction - when you need to react as a variable against imports

I work for a company with a large reaction code base ... not all of them are responsive to standards, and not all of them adhere to their own standards (they think this is pretty standard haha).

I see that the reaction gets involved in the components in different ways. Here are two examples - marked (1) and (2):

(1) let React = require('react'); (2) import React, {Component, PropTypes} from 'react'; 

What is the difference and why use one of them? This is not only react input. I also see import {Component, PropTypes} from 'react'; and let {Component} = React; .

I did a short search on them on the net and could not find what I was looking for. maybe my search terms are a bit. I will be happy to have a short explanation and hopefully documentation to go with it. Thanks.

+5
source share
2 answers

The difference between the two is that

 1) let React = require('react'); 

is ES5 syntax whereas

 2) import React, {Component, PropTypes} from 'react'; 

- ES6 syntax

However, no Javascript engine yet supports ES6, and therefore some utilities, such as babel behind the scenes, convert the ES6 definition to ES5 require syntax, which @azium talks about Node commonJS syntax for importing only modules.

+5
source
  • 1) is the syntax of ECMAScript 5 (ES5) published in 2009.
  • 2) is the syntax of ECMAScript 6 (ES6), also known as ECMAScript 2015 (ES2015), published in 2015.
 (1) let React = require('react'); (2) import React, {Component, PropTypes} from 'react'; 
0
source

All Articles