I work at a company with a large react code base... not all of it is to react standards, and not all of it adheres to it's own standards (im thinking this is pretty standard haha).
I see react being brought into components differently throughout. Here's two examples - marked with (1) and (2):
(1) let React = require('react');
(2) import React, {Component, PropTypes} from 'react';
What is the difference and why use one versus the other? It's not only the react
being brought in. I also see import {Component, PropTypes} from 'react';
and let {Component} = React;
.
I did a brief search on them internets and couldnt find what i was looking for. maybe my search terms are off a bit. Id be happy with brief explanation and hopefully documentation to go with it. Thank you.
The difference between the two is that
1) let React = require('react');
is ES5 syntax, whereas
2) import React, {Component, PropTypes} from 'react';
is ES6 syntax
However no Javascript engine as yet supporst ES6 and hence some utility tools like babel behind the scenes convert the ES6 definition to the ES5 syntax of require which @azium says is the Node commonJS syntax for importing modules only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With