当前位置:网站首页>Extension fragment
Extension fragment
2022-07-01 04:27:00 【fang·up·ad】
background
jsx Grammar requires return There can only be one root tag .App.js Used to assemble other components ,render Methodical return It usually takes a div Root tag , Self written for each component render Methodical return They all need one div Root tag . This can lead to div Too much nesting .
import React, { Component, Fragment } from 'react' import Demo from './04-fracment' export default class App extends Component { render() { return ( <div> <Demo /> </div> ) } }
terms of settlement
1. Use Fragment Can solve this problem .
Fragment The label is a label in form , however reaxt It will be removed automatically during parsing , It's like a place holder .
Every return Use Fragment As a root tag , When parsing react Will take out Fragment label .
import React, { Component, Fragment } from 'react' import Demo from './04-fracment' export default class App extends Component { render() { return ( <Fragment> <Demo /> </Fragment> ) } }
here , No more div label
2. Use empty tags
The effect is the same Fragment. The main difference is Fragment Tags can be added with an attribute key. Empty labels cannot be added . When you need to traverse page nodes ,Fragment Must give a unique key value .
<> <Demo /> </>
边栏推荐
- TCP server communication flow
- 2022 t elevator repair question bank and simulation test
- OSPF notes [dr and bdr]
- Learn Chapter 20 of vue3 (keep alive cache component)
- This may be your last chance to join Tencent
- mysql 函数 变量 存储过程
- Coinbase in a bear market: losses, layoffs, stock price plunges
- What are permissions? What are roles? What are users?
- Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
- [untitled]
猜你喜欢
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
【LeetCode】100. Same tree
Grey correlation cases and codes
【人话版】WEB3黑暗森林中的隐私博弈
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
Daily question - line 10
Task04 | statistiques mathématiques
js 图片路径转换base64格式
Internet winter, how to spend three months to make a comeback
随机推荐
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
Some small knowledge points
类和对象收尾
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
Seven crimes of counting software R & D Efficiency
Recommend the best product development process in the Internet industry!
TASK04|數理統計
Maixll dock quick start
Embedded System Development Notes 80: using QT designer to design the main interface
尺取法:有效三角形的个数
674. longest continuous increasing sequence force buckle JS
[Master / slave] router election in DD message
What is uid? What is auth? What is a verifier?
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
OdeInt与GPU
JS image path conversion Base64 format
mysql 函数 变量 存储过程
This may be your last chance to join Tencent
1. Mobile terminal touch screen event
采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势