What is React?

React is a JavaScript library for building user interfaces, especially for single-page applications. It lets you build components that manage their own state and compose them to create complex UIs.

Creating Your First React App (with Vite)

โœ… 1.1 Install Node.js

React projects require Node.js to run. If you haven’t installed it:

๐Ÿ‘‰ Download and install it from: https://nodejs.org
(Choose the LTS version)

After installation, run this command in your terminal to verify:

node -v
npm -v

โœ… 1.2 Create a React App using Vite

Vite is a fast build tool that’s perfect for starting a React project.

Open your terminal and type the following:

npm create vite@latest my-react-app -- --template react

You’ll be prompted to enter a project name (my-react-app is fine). After it’s done:

cd my-react-app
npm install
npm run dev

โœ… 1.3 Folder Structure

Youโ€™ll see something like this inside the my-react-app folder:

my-react-app/
โ”œโ”€โ”€ index.html        โ†’ The main HTML template
โ”œโ”€โ”€ package.json      โ†’ Project metadata and dependencies
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ App.jsx       โ†’ Main App component (edit this)
โ”‚   โ””โ”€โ”€ main.jsx      โ†’ Entry point (React renders App here)

โœ… 1.4 How It Works

Letโ€™s open the file src/App.jsx. Youโ€™ll see something like this:

function App() {
  return (
    <div>
      <h1>Vite + React</h1>
      <p>Hello world!</p>
    </div>
  );
}

export default App;

App is your first React component.

It returns JSX โ€” it looks like HTML but is JavaScript under the hood.

This App component is rendered inside the <div id="root"></div> in index.html.

โœ… 1.5 Editing the App

Now edit App.jsx to try this:

function App() {
  const name = "React Beginner";

  return (
    <div>
      <h1>Welcome, {name}!</h1>
      <p>This is your first React app.</p>
    </div>
  );
}

export default App;
  • This demonstrates JSX with a JavaScript variable.
  • Save the file and your browser will auto-refresh.

๐Ÿง  Key Concepts You Just Learned:

ConceptMeaning
ViteA fast development tool to create and run React apps
ReactA JavaScript library for building UIs
JSXHTML-like syntax that lets you write UI in JavaScript
ComponentA function that returns UI elements (like <App />)
useState(Coming soon) A React Hook for managing data in components

Keep Learning ๐Ÿ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *