Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native what is type Props?

today I made a new React Native app and noticed something different than the last time I created a native app.

type Props = {}
export default class App extends Component<Props> {}

What type Props = {}; is? I can't really find anything about it.

like image 306
Istvan Orban Avatar asked Feb 03 '23 22:02

Istvan Orban


2 Answers

The code is using Flow, and this is how you give the types of the props the component has. This particular component doesn't have any props.

like image 84
Tholle Avatar answered Feb 06 '23 14:02

Tholle


In TypeScript, there are a lot of basic types, such as string, boolean, and number.

Also, in TypeScript, there are advanced types and in these advanced types, there is something called type aliases.

With type aliases, you can create a new name for an existing type, any valid TypeScript type but you can't define a new type.

For example you can use the type alias chars for the string type:

type chars = string;
let messsage: chars; // same as string type

Or the type alias Props as an object:

type Props = {
    src: string
    alt: string 
}   
export default function Image({src, alt}: Props) {   
    return (
        <img alt={alt} src={src}/>
    )   
}
like image 32
kon_kon Avatar answered Feb 06 '23 14:02

kon_kon