博客
关于我
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/

你可能感兴趣的文章
Openlayers实战:加载Bing地图
查看>>
Openlayers实战:加载CSV文件
查看>>
Openlayers实战:加载GeoJSON
查看>>
Openlayers实战:加载geoserver发布的WMS数据
查看>>
Openlayers实战:加载GPX文件
查看>>
Openlayers实战:加载SHP文件
查看>>
Openlayers实战:加载高德地图
查看>>
Openlayers实战:双击鼠标显示信息名片
查看>>
Openlayers实战:右键点击,弹出feature信息
查看>>
Openlayers实战:测量长度,测量面积
查看>>
Openlayers实战:点击某点,overlay显示经纬度坐标
查看>>
Openlayers实战:界面控制综合演示
查看>>
Openlayers实战:移动鼠标至重叠几何图形上,获取多层所有features信息
查看>>
Openlayers实战:绘制图形,导出geojson文件
查看>>
Openlayers实战:绘制图形,导出KML文件
查看>>
Openlayers实战:绘制多边形,导出CSV文件
查看>>
Openlayers实战:绘制带箭头的线
查看>>
Openlayers实战:绘制点、线、圆、多边形
查看>>
Openlayers实战:绘制矩形,正方形,正六边形
查看>>
Openlayers实战:自定义放大缩小,显示zoom等级
查看>>