fragment是react中的一个组件,作用是代替div作为外层,可做不可见的包裹元素。定义组件的时,return返回需要唯一根元素,所以经常会写一个div来包裹,但如果不想渲染这个div,减少dom渲染,就可以引用Fragment组件。

推荐教程:《React视频教程》
fragment是react中的一个组件,作用是代替div作为外层,可做不可见的包裹元素。
React中一个组件往往要返回多个元素,同时,React又要求这些元素必须被包裹在一个元素下,最普遍的做法是用
从react 16开始, render支持返回数组:
import React from 'react'; export default function () { return [ 一步 01, 一步 02, 一步 03, 一步 04 ]; }
同时,也提供了另一种方法,那就是Fragments。
在我们定义组件的时候,return返回需要唯一根元素,所以我们经常会写一个div来包裹,,如果我们不想渲染这个div,减少dom渲染,就可以引用Fragment组件。
import React from 'react'; export default function () { return ( 一步 01 一步 02 一步 03 一步 04 ); }
更多编程相关知识,请访问:编程入门!!
The above is the detailed content of What is fragment in react?. For more information, please follow other related articles on the PHP Chinese website!
How to solve the problem that js code cannot run after formatting
The latest ranking of the top ten exchanges in the currency circle
How long does it take for Douyin recharge to arrive?
What are the 8 data types of redis
How to use excel macros
cdr file opening method
Detailed explanation of Linux fork function
How to convert wav format