React Native 究竟是什么<>(空)组件 [英] React Native what exactly is the <> (empty) component

查看:18
本文介绍了React Native 究竟是什么<>(空)组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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 究竟是什么&lt;&gt;(空)组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆