Begin React
What is React?
React is a JavaScript library used for creating user interfaces, mostly web applications.
Think of React as a tool that helps you build websites with small pieces (components) instead of one big lump of JavaScript and HTML.
Why Use React? (Benefits)
- Reusable Components: Write once and use it everywhere.
- Fast Updates: React updates only the parts that change, not the whole page.
- Community Help: Many developers use it, so help is easily found.
- Simple Project Management: With component-based architecture, everything is neatly structured.
Building a React App with TypeScript
Step-by-Step
1️. Install Node.js
Download and install Node.js from:
2️. Build a React + TypeScript App
Open your terminal (Command Prompt, PowerShell, or VS Code's terminal) and run:
npm create vite@latest my-react-app -- --template react-ts
-my-react-app is the directory name. You can name it whatever
you like.
3️. Enter your project
cd my-react-app
4️.install required packages
npm run install
5️.
Start the development
server
npm run dev
Now your React application is up and running!
Use the link that is shown in the terminal (usually
http://localhost:5173).
Flow of the React project
my-react-app/
├── node_modules/ # Installed packages
├── public/ # Static files like favicon,
logos, and files that are commonly used
│ └── vite.svg
├── src/ # Main source code
│ ├── assets/ #
Images, fonts, Icons, etc.
│ │ └── logo.png
│ ├── components/ #
Your UI components (create this folder later)
│ ├── scripts/ #
Utility JS/TS files (custom functions/helpers), Store how the project runs
│ │ └── sayHello.ts
│ ├── App.tsx #
Main component
│ ├── main.tsx #
Entry point (renders <App />)
│ └── index.css # Global styles
├── .gitignore # Files Git should ignore, Large
and Sensitive data
├── package.json # App metadata & dependencies,
the way how the React application runs
├── tsconfig.json # TypeScript configuration
└── vite.config.ts
# Vite configuration
Sample React project snippet
React Hello World Code Flow:
-
React is imported → So we can write React code.
-
ListGroup is imported → It’s a custom component you made (like a reusable block).
-
We create a function called
App
→ This is your main screen or main component. -
Inside
App
Return the UI:-
A heading that says Hello World!
-
The
ListGroup
component (whatever it shows).
-
-
The
<>...</>
is used to group both items without adding extra tags (it's called a Fragment). -
Finally, we write
export default App
→ So this component can be used to show the app in the browser.
Other tip---
Version Control is what?
- Replay earlier versions
- Work easily with others
- Keep your code history safe
- The most popular version control system is Git.
Comments
Post a Comment