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