当前位置:网站首页>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 /> </>
边栏推荐
- How to choose the right server for website data collection?
- Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address
- LeetCode 1827. Increment array with minimal operation
- [deep learning] (4) decoder mechanism in transformer, complete pytoch code attached
- Advanced application of ES6 modular and asynchronous programming
- Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
- "Target detection" + "visual understanding" realizes the understanding of the input image
- 小程序中自定义组件
- 2022年上海市安全员C证考试题模拟考试题库及答案
- Learn Chapter 20 of vue3 (keep alive cache component)
猜你喜欢

Possible problems and solutions of using scroll view to implement slider view

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试

软件研发的十大浪费:研发效能的另一面

DO280管理应用部署--RC

Class and object finalization

Odeint et GPU

测量三相永磁同步电机的交轴直轴电感

After many job hopping, the monthly salary is equal to the annual salary of old colleagues

类和对象收尾
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
随机推荐
slf4j 简单实现
[leetcode skimming] February summary (updating)
Offline installation of Wireshark 2.6.10
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
HoloLens2开发环境搭建及部署app
JS rotation chart
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
Loop filtering based on Unet
[godot] unity's animator is different from Godot's animplayer
OSPF notes [multiple access, two multicast addresses with OSPF]
Annual inventory review of Alibaba cloud's observable practices in 2021
2022年上海市安全员C证考试题模拟考试题库及答案
CF1638E colorful operations
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
Redis (VII) optimization suggestions
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
NFT:使用 EIP-2981 开启 NFT 版税之旅
Qt development experience tips 226-230
2022 t elevator repair question bank and simulation test
Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale

