Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

const App: () => React$Node = () => {...}: what does it mean this instruction?

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 = () => {...} 

What does it mean this instruction?

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

like image 850
marco Avatar asked Oct 07 '19 20:10

marco


People also ask

What does const in React mean?

const is a signal that the variable won't be reassigned. let is a signal that the variable may be reassigned.

What is a React node?

A React node is defined as: a light, stateless, immutable, virtual representation of a DOM node. React nodes are not real DOM nodes (e.g., text or element nodes) themselves, but a representation of a potential DOM node. The representation is considered the virtual DOM.

What is React in Softwaredevelopment?

React is a JavaScript-based UI development library. Facebook and an open-source developer community run it. Although React is a library rather than a language, it is widely used in web development. The library first appeared in May 2013 and is now one of the most commonly used frontend libraries for web development.

What is node type in react native?

A React Node is one of the following types: Boolean (which is ignored) null or undefined (which is ignored) Number. String.


Video Answer


1 Answers

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, .etc), ReactFragment, React.Portal, boolean, null, undefined

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.

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

like image 81
Lukáš Gibo Vaic Avatar answered Sep 20 '22 02:09

Lukáš Gibo Vaic