Two ways to use react in React html

Two ways to use react in React html

Basic Use

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>hello</title>
</head>

<body>
  <div id="app">

  </div>
  <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script type="text/babel">
    // Virtual dom
    const str = 'hello react'
    const vDom = <h1>{str}</h1>
    // const vDom = <pppp>hello react</pppp>
    //Convert the virtual dom into the real dom
    ReactDOM.render(vDom, document.getElementById("app"))
  </script>
</body>

</html>

Two ways to create a virtual DOM

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>hello</title>
</head>

<body>
  <div id="app">

  </div>
  <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script>
    // The first pure js creation (generally not used)
    // Virtual dom
    const str = 'hello react'
    const vDom = React.createElement('h1', {
      id: 'myId'
    }, str)
    // const vDom = <pppp>hello react</pppp>
    //Convert the virtual dom into the real dom
    ReactDOM.render(vDom, document.getElementById("app"))
    // 
  </script>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>hello</title>
</head>

<body>
  <div id="app">

  </div>
  <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script type="text/babel">
    // The first pure js creation (generally not used)
    // [] ul li use forEach to implement var names = ['Zhang Fei', 'Guan Yu', 'Zhao Yun']
    const ul = <ul>
      {
        names && names.map((name,index)=>
          <li key={index}>
            {name}
          </li>
        )
      }
    </ul>
    ReactDOM.render(ul,document.getElementById("app"))
    // 
  </script>
</body>

</html>

Knowledge point expansion:

React pwa configuration

Add the plugin to the webpack configuration file

const WorkboxWebpackPlugin = require('workbox-webpack-plugin')
plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].css'
    }),
    new WorkboxWebpackPlugin.GenerateSW({
      clientsClaim:true,
      skipWaiting:true
    })
  ],

This is the end of this article about two ways to use react in React html. For more relevant content about using react in React html, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Teach you how to implement a react from html
  • How to remove HTML tags in rich text and filters in Vue, React, and WeChat applets
  • Do you know how to use React in HTML pages?

<<:  Two methods to implement Mysql remote connection configuration

>>:  Linux centOS installation JDK and Tomcat tutorial

Recommend

Introduction to Docker Architecture

Docker includes three basic concepts: Image: A Do...

How to use border-image to implement text bubble border sample code

During the development activity, I encountered a ...

MySQL count detailed explanation and function example code

Detailed explanation of mysql count The count fun...

Implementation of socket options in Linux network programming

Socket option function Function: Methods used to ...

A brief discussion on the maximum number of open files for MySQL system users

What you learn from books is always shallow, and ...

MySQL slow query method and example

1. Introduction By enabling the slow query log, M...

How to purchase and install Alibaba Cloud servers

1. Purchase a server In the example, the server p...

SQL implementation of LeetCode (175. Joining two tables)

[LeetCode] 175.Combine Two Tables Table: Person +...

Overview of time configuration under Linux system

1. Time types are divided into: 1. Network time (...

Summary of the differences between global objects in nodejs and browsers

In Node.js, a .js file is a complete scope (modul...

Detailed explanation of MySQL combined query

Using UNION Most SQL queries consist of a single ...

How to modify iTunes backup path under Windows

0. Preparation: • Close iTunes • Kill the service...