typescript types react code example

Example 1: React with Typescript

// to create a simple app with React and Typescript
npx create-react-app yourProjectName --template typescript

// to add Typescript in an existing project
npm install --save typescript @types/node @types/react @types/react-dom @types/jest

Example 2: react tsx component example

import React from 'react';

interface Props {
}

const App: React.FC<Props> = (props) => {
  return (
    <div><div/>
  );
};

export default App;

Example 3: why use typescript with react

npm install --save typescript @types/node @types/react @types/react-dom @types/jest