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
.
const is a signal that the variable won't be reassigned. let is a signal that the variable may be reassigned.
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.
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.
A React Node is one of the following types: Boolean (which is ignored) null or undefined (which is ignored) Number. String.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With