博客
关于我
React 学习笔记 —— Fragment
阅读量:563 次
发布时间: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/

你可能感兴趣的文章
Mysql学习总结(53)——使用MySql开发的Java开发者规范
查看>>
Mysql学习总结(54)——MySQL 集群常用的几种高可用架构方案
查看>>
Mysql学习总结(55)——MySQL 语句大全再温习
查看>>
Mysql学习总结(56)——MySQL用户管理和权限设置
查看>>
Mysql学习总结(57)——MySQL查询当天、本周、本月、上周、本周、上月、距离当前现在6个月数据
查看>>
Mysql学习总结(58)——深入理解Mysql的四种隔离级别
查看>>
Mysql学习总结(59)——数据库分库分表策略总结
查看>>
Mysql学习总结(5)——MySql常用函数大全讲解
查看>>
Mysql学习总结(60)——并发量大、数据量大的互联网业务数据库设计规范总结
查看>>
Mysql学习总结(61)——MySQL优化之DBA级优化整理汇总
查看>>
Mysql学习总结(62)——MySQL连接com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link问题
查看>>
Mysql学习总结(63)——Mysql数据库架构方案选择与分析
查看>>
Mysql学习总结(64)——Mysql配置文件my.cnf各项参数解读
查看>>
Mysql学习总结(65)——项目实战中常用SQL实践总结
查看>>
Mysql学习总结(66)——设置MYSQL数据库编码为UTF-8
查看>>
Mysql学习总结(67)——MYSQL慢查询日志
查看>>
Mysql学习总结(68)——MYSQL统计每天、每周、每月、每年数据 SQL 总结
查看>>
Mysql学习总结(69)——Mysql EXPLAIN 命令使用总结
查看>>
Mysql学习总结(6)——MySql之ALTER命令用法详细解读
查看>>
Mysql学习总结(70)——MySQL 优化实施方案
查看>>