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 究竟是什么<>(空)组件
基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
