A brief introduction to React

A brief introduction to React

1. CDN introduction

Like ordinary JS libraries or frameworks, React can also be imported from CDN.

Before using CDN to import, you need to understand two types of JS files, one is cjs and the other is umd.

cjs: The full name is CommonJS, which is the module specification supported by Node.js

umd: The full name is Universal Module Definition, which is a unified module definition that includes cjs used by Node.js and is compatible with module specifications including browsers and Node.js.

New module convention: The latest module convention is to use import and export keywords.

Therefore, when introducing React, the umd version is generally used first, which can support both Node.js and browsers.

React's CDN introduction requires the introduction of two JS library files, react and react-dom. Here we take BootCDN introduction as an example.

In the following imports, the umd version is also introduced, and the import order must be to introduce react first and then react-dom.

1.1 react (import first)

There are development and production versions here. One is the developer version and the other is the product version. Both are fine. The product version may have more complete functions than the developer version, but it takes up more memory. Here we take the introduction of the production version as an example:

<script src="https://cdn.bootcss.com/react/16.13.1/umd/react.production.min.js"></script>

1.2 react-dom (introduced later)

The introduction method of react and react-dom is similar to the above. The production version should be the umd version. It is best if the version number is the same as that of react.

<script src="https://cdn.bootcss.com/react-dom/16.13.1/umd/react-dom.production.min.js"></script>

1.3 Check whether react is successfully introduced

<script>
  console.log(React);
  console.log(ReactDOM);
</script>

If you can successfully import the two objects React and ReactDOM, the introduction is successful!

2. Webpack introduction

Use import ... from in the Webpack configuration environment. The command is as follows:

//Install react react-dom
yarn add react react-dom

//Introduce react react-dom
import React from "react"
import ReactDOM from "react-dom"

In addition to Webpack, rollup and parcel also support the above-mentioned import method.

3. create-react-app

Webpcak is more flexible for veterans to introduce React, but for novices, the configuration of Webpack is very complicated. In order to introduce React, it is necessary to configure the complex Webpack, which makes it more difficult. Therefore, just like Vue is equipped with Vue cli, React is also equipped with a standard tool for React development, namely the create-react-app tool, which is similar to Vue cli. Both have built-in Webpack, which helps us configure the React development environment and can be used directly.

For beginners, the create-react-app tool is easier to use.

//Globally install create-react-app
yarn global add create-react-app

// Check the version number create-react-app --version

//Create a React file, enter the directory to be created, and execute the create command create-react-app project name

The above is a brief introduction to the details of the introduction of React. For more information about the introduction of React, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to introduce scss into react project
  • How to introduce Angular components in React
  • React introduces container components and display components to Vue
  • React internationalization react-intl usage
  • React Synthetic Events Explained
  • A brief comparison of Props in React
  • Detailed explanation of the solution for migrating antd+react projects to vite
  • Reasons and solutions for the failure of React event throttling effect
  • React implementation example using Amap (react-amap)

<<:  MySQL 8.0.11 MacOS 10.13 installation and configuration method graphic tutorial

>>:  Steps to enable TLS in Docker for secure configuration

Recommend

The latest virtual machine VMware 14 installation tutorial

First, I will give you the VMware 14 activation c...

How to implement an array lazy evaluation library in JavaScript

Table of contents Overview How to achieve it Spec...

Share the 15 best HTML/CSS design and development frameworks

Professional web design is complex and time-consu...

MySQL learning notes: data engine

View the engines supported by the current databas...

Detailed explanation of MySQL/Java server support for emoji and problem solving

This article describes the support and problem so...

SQL implementation of LeetCode (184. The highest salary in the department)

[LeetCode] 184. Department Highest Salary The Emp...

How to install and configure mysql 5.7.19 under centos6.5

The detailed steps for installing mysql5.7.19 on ...

Detailed explanation of soft links and hard links in Linux

Table of contents 1. Basic storage of files and d...

Nginx cache files and dynamic files automatic balancing configuration script

nginx Nginx (engine x) is a high-performance HTTP...

Native JS to implement paging click control

This is an interview question, which requires the...

A brief discussion on the solution of Tomcat garbled code and port occupation

Tomcat server is a free and open source Web appli...

Detailed explanation of how to create an updateable view in MySQL

This article uses an example to describe how to c...

HTML tutorial, HTML default style

html , address , blockquote , body , dd , div , d...