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
1. Vue--The first vue-cli program The development...
Table of contents Native JS How to send a get req...
When we use the folder properties dialog box in Wi...
Generally speaking, we can have the following two...
In the MySQL database, null is a common situation...
1. The startup menu is to move the cursor to the ...
Install First you need to install Java and Scala,...
<br />Original URL: http://www.lxdong.com/po...
1. Connect Centos7 under VMware and set a fixed I...
Preface When docker run creates and runs a contai...
1. Tomcat service is not open Enter localhost:808...
Download: http://dev.mysql.com/downloads/mysql/ U...
Setting min-width and max-width properties in tab...
What is Vite? (It’s a new toy on the front end) V...
Table of contents Overview Property settings Proc...