1. Basic understanding of React1. IntroductionReact is a JavaScript library for building user interfaces (focusing only on view) open sourced by Facebook 2. Features of React
3. Reasons why React is efficient
2. Basic Use of React1. Related js libraries
2. Import the js library into the page<script src="../js/react.development.js"></script> <script src="../js/react-dom.development.js"></script> <script src="../js/babel.min.js"></script> 3. Coding<script type="text/babel"> //Must declare babel // 1. Create a virtual DOM element const vDom = <h1>Hello React</h1> // Do not add quotes // 2. Render the virtual DOM to the real DOM container of the page ReactDOM.render(vDom, document.getElementById('test')) </script> React JSX1. Virtual DOMReact provides some APIs to create a special general js object var element = React.createElement('h1', {id:'myTitle'},'hello') What is created above is a simple virtual DOM object Virtual DOM objects will eventually be converted into real DOM by React When we code, we basically only need to operate the virtual DOM related data of react, and react will convert it into real DOM changes and update the interface 2. JSX
Note 1: It is not a string, nor an Note 2: It ultimately generates a
When encountering a code starting with <, parse it according to the tag syntax: HTML tags with the same name are converted to HTML elements with the same name, and other tags need special parsing When encountering code starting with {, parse it with JS syntax: The JS code in the tag must be enclosed in { }
The browser cannot parse JSX code directly, and needs to be translated into pure JS code by babel before it can run Whenever you use JSX, you must add type="text/babel" to declare that it needs to be processed by Babel 3. Rendering virtual DOM elementsgrammar:
effect: 4. How to create a virtual DOMPure JS methodReact.createElement('h1',{id:'myTitle'}, title The JSX way <h1 id='myTitle'>{title}</h1> Code Sample <div id="app"></div> const test1 = 'MY TEST 1' // 1. Create virtual dom: two methods var element = React.createElement('h3',{id:app},test1) var element2 = <h3 id={test1}>{test1}</h3> // 2. Render virtual dom ReactDOM.render(element, document.getElementById('app')) ReactDOM.render(element2, document.getElementById('app')) 5. Hello World with ReactStep 1: Introduce react.js related libraries <script src="../js/react.development.js"></script> <script src="../js/react-dom.development.js"></script> <script src="../js/babel.min.js"></script> Step 2: Define the root element <div id="app"></div> Step 3: Write React code in babel environment <script type="text/babel"> // 1. Create a virtual DOM element object var vDOM = <h1>Hello W</h1> //Not a string// 2. Render the virtual DOM into the real DOM container of the page ReactDOM.render(vDOM,document.getElementById('app')) </script> This is the end of this article about the detailed notes for beginners of React. This article describes the basic concepts and basic usage of React as well as some commonly used js libraries related to React. I hope it can be helpful to you. You may also be interested in:
|
<<: An example of how Tomcat manages Session
>>: MySQL 8.0.15 installation and configuration graphic tutorial
<br />Hello everyone! It’s my honor to chat ...
1. Overview The so-called life cycle function is ...
The function has been implemented a long time ago...
1. Introduction I won’t go into details about apo...
The difference between CSS3 animation and JS anim...
An index is a sorted data structure! The fields t...
<br />Web Design and Production Test Part I ...
When a website is maliciously requested, blacklis...
Preface Usually, a "paging" strategy is...
1. Goal: Change the value of character_set_server...
This article shares the specific steps of VMware ...
It is troublesome to install the db2 database dir...
This article uses examples to explain the concept...
Table of contents 1. Modify the my.cnf file of se...
As the title says, otherwise when the page is revi...