manuelBetancurt
manuelBetancurt

Reputation: 16168

react native what is the use of React$Node

on React native, by default react-native init project, I see

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

but this is what I used before

const App = () => {

What is that "React$Node" in this context?

Upvotes: 1

Views: 159

Answers (1)

Waheed Akhtar
Waheed Akhtar

Reputation: 3187

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

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

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

If you are confused about the dollar sign, here is a link with an explanation.

https://www.saltycrane.com/flow-type-cheat-sheet/latest/

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

React$Node is a type defined in react.js

 declare type React$Node =
  | null
  | boolean
  | number
  | string
  | React$Element<any>
  | React$Portal
  | Iterable<?React$Node>;

Upvotes: 1

Related Questions