const 应用程序:() =>React$Node = () =>{...}:这个指令是什么意思? [英] const App: () => React$Node = () => {...}: what does it mean this instruction?

查看:89
本文介绍了const 应用程序:() =>React$Node = () =>{...}:这个指令是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

react-native init ProjectName 上,主应用文件 App.js 包含以下方式的组件声明:

on react-native init ProjectName, the main app file App.js contains the declaration of a component in the following way:

const App: () => React$Node = () => {...}

这个指令是什么意思?

我的意思是,我习惯将组件定义为 const App = () =>{...},所以我不明白,特别是之间的表达式:() =>React$Node.

I mean, I'm used to component defined as const App = () => {...}, so I don't understand, in particular, the expression in between: () => React$Node.

推荐答案

它的类型定义来自 Flow,这意味着常量 App 是函数类型,它返回 ReactNode.

Its type definition from Flow, it means that constant App is of type function and it returns ReactNode.

ReactNode 是以下类型之一: ReactChild |反应片段 |反应门户 |布尔值 |空|未定义

ReactNode is one of these types: ReactChild | ReactFragment | ReactPortal | boolean | null | undefined

这意味着 App 可以返回的函数,任何有效的 JSX(在 React Native 中,它来自 View、Text、.etc)、ReactFragment、React.Portal、boolean、null、undefined

This means the function App can return, any valid JSX (in react native its anything from View, Text, .etc), ReactFragment, React.Portal, boolean, null, undefined

如果您对美元符号感到困惑,这里有一个解释链接.https://www.saltycrane.com/flow-type-cheat-sheet/最新/

If you are confused about the dollar sign, here is a link with explanation. https://www.saltycrane.com/flow-type-cheat-sheet/latest/

名称中带有 $ 的私有"或魔法"类型有单独的部分.请参阅此处的注释并在此处发表评论.更新:现在这里记录了一些这些类型.

There are separate sections for "private" or "magic" types with a $ in the name. See the note here and comment here. Update: Some these types are now documented here.

为简单起见,您可以将其视为 React 中的 Node(将其视为作用域/命名空间)

For easy you can think of it as its Node from React (think of it as scope/namespace)

这篇关于const 应用程序:() =>React$Node = () =>{...}:这个指令是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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