react typescript component with props code example
Example 1: typescript react class component
import * as React from 'react';
export interface TestProps {
count: number;
}
export interface TestState {
count: number;
}
class Test extends React.Component<TestProps, TestState> {
state = { count:0 }
render() {
return ( <h2>this is test</h2> );
}
}
export default Test;
Example 2: react typescript props
type CarProps = {
name: string;
brand: string;
price;
}
const Car: React.FC<CarProps> = (props) => {
const { name, brand, price } = props;
}
const Car: React.FC<CarProps> = ({ name, brand, price }) => {
}