Istvan Orban
Istvan Orban

Reputation: 1685

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.

Upvotes: 10

Views: 10402

Answers (2)

kon_kon
kon_kon

Reputation: 21

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}/>
    )   
}

Upvotes: 2

Tholle
Tholle

Reputation: 112807

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.

Upvotes: 11

Related Questions