props in typescript react code example

Example 1: react tsx component example

import React from 'react';

interface Props {
}

const App: React.FC = (props) => {
  return (
    
); }; export default App;

Example 2: 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 3: TYPESCript props class component

class Test extends Component {
  constructor(props : PropsType){
    	super(props)
  }
  
  render(){
   	console.log(this.props) 
    return (
     	

this.props.whatever

) } };

Example 4: ts react props type

type Props = {
  size: string;
}

const Component = ({ size = 'medium' }: Props) => (
  
);

Tags:

Misc Example