react native typescript props 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<CarProps> = (props) => {
  const { name, brand, price } = props;
  // some logic
}

// usage 2
const Car: React.FC<CarProps> = ({ name, brand, price }) => {
	// some logic
}

Example 2: reactnative typescript

npx react-native init MyApp --template react-native-template-typescript

Example 3: get typescript props of component

type ViewProps = React.ComponentProps<typeof View>
// or
type InputProps = React.ComponentProps<'input'>

Example 4: react native typescript

npx --ignore-existing react-native init MyApp --template react-native-template-typescript