React Native what exactly is the lt;gt; (empty) component(React Native 究竟是什么lt;gt;(空)组件)
问题描述
在 React Native 中,您可以将一组组件封装在一个 <View>
(或类似的)组件中.您还可以将一组组件封装为 <>
和 </>
.这些是什么?他们只是转换为基本视图吗?这可能不是一个好的做法,但它不会发出警告,也不会崩溃.
In React Native you can encapsulate a set of components in one single <View>
(or similar) component. You can also encapsulate a set of components as <>
and </>
. What are these? Do they just translate to an base View? It's probably not a good practice but it doesn't give a warning and it doesn't crash.
推荐答案
这是 Fragment
组件的 React 快捷方式.
It's the React shortcut for Fragment
component.
你可以这样写:
import React, { Component } from 'react'
class Component extends Component {
render() {
return <> <ComponentA/> <ComponentB/> </>
}
}
或者不用快捷键,导入Fragment
组件
Or without the shortcut and import Fragment
component
import React, { Component, Fragment } from 'react'
class Component extends Component {
render() {
return <Fragment> <ComponentA/> <ComponentB/> </Fragment>
}
}
你必须知道,你不能使用任何快捷键或道具.
You have to know, you can't use any key or prop with the shortcut syntax.
这里是官方文档
希望对你有帮助!
这篇关于React Native 究竟是什么<>(空)组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:React Native 究竟是什么<>(空)组件


- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01