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

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

Example 2: TYPESCript props class component

class Test extends Component<PropsType,StateType> {
  constructor(props : PropsType){
    	super(props)
  }
  
  render(){
   	console.log(this.props) 
    return (
     	<p>this.props.whatever</p> 
    )
  }
  
};

Example 3: typescript ..otherProps

interface CustomComponentProps  {
  prop1: string; 
  prop2:string;
}
const CustomComponent: React.FC<CustomCompoenetProps & Record<string,any>>  = ({prop1,prop2, ...otherProps}) =>  {
  retrun (
    <>
      <Component prop1={prop1} prop2={prop2} {...otherProps}/>
    </>
  );

} 
export default CustomComponent