Introduction
This tutorial will guide you through setting up a React project with TypeScript.
Prerequisites
- Node.js installed (v18 or higher)
- Basic knowledge of JavaScript
- Familiarity with command line
Step 1: Create a New Project
npm create vite@latest my-react-app -- --template react-ts
cd my-react-app
npm install
Step 2: Project Structure
Explain the project structure and key files.
Step 3: Creating Your First Component
import React from 'react';
interface Props {
name: string;
}
const Greeting: React.FC<Props> = ({ name }) => {
return <h1>Hello, {name}!</h1>;
};
export default Greeting;
Step 4: Running the Development Server
npm run dev
Conclusion
You’ve successfully set up a React project with TypeScript! Continue learning by exploring more advanced topics.
Next Steps
- Learn about React Hooks
- Explore state management
- Build a complete application