当前位置:网站首页>Basic use of JSX
Basic use of JSX
2022-06-29 04:07:00 【Snow and ice LB】
JSX Basic use of
JSX yes JavaScript XML Abbreviation , It means that JavaScript The code says XML ( HTML) Format code
advantage : Declarative syntax is more intuitive 、 And HTML Structure is the same , Reduce the cost of learning 、 Improve development efficiency

Use steps
- Use JSX Syntax creation react Elements
const title = <h1> hello JSX </h1>
- Use ReactDom.render() Method rendering react Elements into the page
ReactDom.render(title, root)
Why can be used in scaffolding JSX grammar ?
JSXIt's not standardECMAScriptgrammar , It isECMAScriptGrammar extension of .- Need to use
babelAfter compiling and processing , To use... In a browser environment . create-react-appThis configuration is already in the scaffold by default , No manual configuration required .- compile JSX My bag is @bable/preset-react
The embedded JS expression
- Data exists
JSin - grammar :
{ JavaScript expression } - Be careful : In grammar is
Single braces, NoDouble brace! and vue Dissimilarity
import React from "react";
import ReactDOM from "react-dom";
// JSX Use in JavaScript expression
const name = 'Jack'
const title =(
<h1 className="title">
Hello, {
name }
</h1>
)
// Rendering react Elements
ReactDOM.render(title, document.getElementById('root'))
JSX List rendering of
If you want to render a set of data , Array should be used map() Method
Be careful : When rendering the list, you should add key attribute ,key The value of the attribute must be unique
principle :map() Traverse who , Just add... To anyone key attribute
Be careful : Try to avoid using index numbers as key
// The list of rendering
const songs = [
{
id: 1, name: ' Face without makeup '},
{
id: 2, name: ' legend '},
{
id: 3, name: ' get rid of-blues '}
]
const list = (
<ul>
{
songs.map( item => <li key={
item.id}>{
item.name }</li> ) }
</ul>
)
JSX Style processing for
- Inline style ——style
<h1 style={
{
color: 'red', backgroundColor: 'skyblue' }}>
JSX Style processing for
</h1>
- Class name ——className 【 recommend 】
<h1 className="title">
JSX Style processing for
</h1>
JSX summary
- JSX yes React The core content .
- JSX It means that JS The code says HTML structure , yes React Declarative expression .
- Use JSX Fit embedded JS expression 、 Conditions apply colours to a drawing 、 The list of rendering , Can describe any UI structure .
- Recommended className The way to JSX Add the style .
- React Make full use of JS The ability of the language itself to write Ul, Instead of building wheels HTML function .
边栏推荐
- 5-minute NLP: summary of time chronology from bag of words to transformer
- My creation anniversary
- 不使用union实现Mysql 列转行
- Analysis on the types of source code anti leakage technology
- Nuxt - set SEO related tags, page titles, icons, etc. separately for each page (page configuration head)
- Error accessing database
- How to keep database and cache consistent
- 人大金仓(KingBase)导出表结构
- Webassembly learning - dynamic linking
- Data collection and management [6]
猜你喜欢

百度智能云服务网格产品CSM发布 | 火热公测中

Establishment of small and medium-sized enterprise network

MySQL复习资料(附加)case when

Apifox : 不仅是Api调试工具,更是开发团队的协作神器

基于可变参模板实现的线程池
![[filter design] customize the filter with MATLAB according to the design index](/img/b2/b5576c5eb6dbe9a0c64158802aa1d0.png)
[filter design] customize the filter with MATLAB according to the design index

iNFTnews | 元宇宙技术将带来全新的购物体验

How to merge upstream and downstream SQL data records
![[FPGA mathematical formula] use FPGA to realize common mathematical formulas](/img/b9/e6f219738b106a96b0f5323ee61cca.png)
[FPGA mathematical formula] use FPGA to realize common mathematical formulas

How to keep database and cache consistent
随机推荐
[filter design] customize the filter with MATLAB according to the design index
【Laravel系列8】走出 Laravel 的世界
Analysis on the types of source code anti leakage technology
Ask the handler about the memory leak scenario in the interview. Don't just know static internal classes & weak references!
Data statistical analysis (SPSS) [8]
人大金仓(KingBase)导出表结构
百度智能云服务网格产品CSM发布 | 火热公测中
增额终身寿险下架了吗?现在还有哪些增额终身寿险产品?
Call snapstateon closed sou from Oracle CDC
Microsecond TCP timestamp
Live broadcast preview | neurips special session I & Young Scientists special session
Data collection and management [6]
MySQL review materials (additional) case when
云主机mysql在本地电脑连接不上
你为什么做测试/开发程序员?还能回想出来吗......
How to back up all data on Apple mobile phone in 2 steps (free)
C language -- branch structure
logstash启动过慢甚至卡死
Here comes Wi Fi 7. How strong is it?
New listing of operation light 3.0 -- a sincere work of self subversion across the times