M
M
Mark2019-04-27 21:33:48
React
Mark, 2019-04-27 21:33:48

What's the difference between connecting react via console and via link?

Sorry for the stupid question, I'm still a teapot in reat. What's the difference between react pidkey via console and via link?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-28
@marki1404

Your question has nothing to do with React itself. The question is rather about the types of modules and how to use them. By reference, you include a UMD module, and React will be available as a global React or window.React object. You can work with such a module even from the script tag in the html file:

<script crossorigin src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script>
  function Greetings(props) {
    return React.createElement('div', null, 'Hello, World!');
  }
</script>

When you install React as an npm package. 5 versions of the React module are installed in the node_modules folder:
2 versions of the CommonJS modules: production and development and 3 versions of the UMD: production, development and profiling.
The package itself exports the CommonJS module by default. The version is exported depending on the process.env.NODE_ENV environment variable:
'use strict';

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react.production.min.js');
} else {
  module.exports = require('./cjs/react.development.js');
}

You use the CommonJS module when you write imports from the package root in the code: As a rule, modern front-end development uses the ES6 module system, experimental syntax, and such code requires translation into cross-browser code and assembly. Babel and webpack are now the industry standard. I advise you to read this article from Yandex about the evolution of JavaScript modular systems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question