props type react typescript code example
Example 1: react typescript props
// Declare the type of the props
type CarProps = {
name: string;
brand: string;
price;
}
// usage 1
const Car: React.FC = (props) => {
const { name, brand, price } = props;
// some logic
}
// usage 2
const Car: React.FC = ({ name, brand, price }) => {
// some logic
}
Example 2: ts react props type
type Props = {
size: string;
}
const Component = ({ size = 'medium' }: Props) => (
);