博客
关于我
React 学习笔记 —— Fragment
阅读量:556 次
发布时间:2019-03-09

本文共 1071 字,大约阅读时间需要 3 分钟。

Handling Multiple Roots in React JSX

In React's JSX syntax, it's essential to use a single root tag. To avoid unnecessary extra div tags and hierarchical structures, we can use two main approaches.

Fragment Approach

The Fragment component is designed to be ignored in rendering. It allows embedding multiple root components without adding extra DOM nodes to the tree. Perfect for when you need to #[key] your fragments. If you have loops and dynamic content, specify the key attribute for each fragment is crucial.

Example:

import {Fragment} from 'react';...      test     test

Empty Tag Approach

Using empty tags is another great way to embed multiple root nodes without creating real DOM elements. They don’t accept any attributes since they’re meant purely for embedding HTML.

Example:

...   test   test

The key difference between Empty Tags and Fragments is that Fragments can only accept **key** attribute, which is important when you're dealing with list-like structures. However, Empty Tags have no such limitations and are often used for simple content embedding.

转载地址:http://ajxpz.baihongyu.com/

你可能感兴趣的文章
vscode中快速生成vue模板
查看>>
QT报make: Circular all <- first dependency dropped.错误解决。
查看>>
demo---购物车的多条记录保存(cookie)
查看>>
参考图像
查看>>
*.json: [“usingComponents“][“van-button“] 未找到
查看>>
设计模式(18)——中介者模式
查看>>
用JavaScript实现希尔排序
查看>>
python初学者容易犯的错误
查看>>
error LNK2019:无法解析的外部符号_imp_CryptAcquireContextA@20
查看>>
Qt之QImage无法获取图片尺寸(宽和高)
查看>>
推荐几篇近期必看的视觉综述,含GAN、Transformer、人脸超分辨、遥感等
查看>>
ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED
查看>>
Java-类加载过程
查看>>
BUU-MISC-认真你就输了
查看>>
BUU-MISC-caesar
查看>>
【专题2:电子工程师 之 上位机】 之 【36.事件重载】
查看>>
【专题3:电子工程师 之 上位机】 之 【46.QT音频接口】
查看>>
一文学会JVM常见参数设置+调优经验(JDK1.8)
查看>>
一文理解设计模式--命令模式(Command)
查看>>
VTK:可视化之RandomProbe
查看>>