02-getting-started.html
html9 kB184 linesIn Tutorial.zip
Tutorial.zip02-getting-started.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Getting Started - React Tutorial</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<header>
<h1>⚛️ Getting Started with React</h1>
<p>Chapter 2 of 15</p>
</header>
<div class="content">
<h2>Installation</h2>
<p>To use React in production, you need <strong>npm</strong> which is included with Node.js. If you don't have Node.js installed, download it from <a href="https://nodejs.org/" target="_blank">nodejs.org</a>.</p>
<div class="info-box">
<strong>💡 Tip:</strong> Make sure you have Node.js version 14.0 or higher installed. You can check your version by running <code class="inline-code">node --version</code> in your terminal.
</div>
<h2>⚡ Create a React Application with Vite</h2>
<p>The <strong>fastest</strong> and most modern way to create a React application is by using <strong>Vite</strong> - a next-generation build tool that provides instant server start and lightning-fast Hot Module Replacement (HMR).</p>
<div class="info-box">
<strong>🚀 Why Vite?</strong> Vite offers instant server start, blazing-fast HMR, and optimized builds. It's becoming the industry standard for React development!
</div>
<p>To create a React application with Vite, run the following command in your terminal:</p>
<pre><code>npm create vite@latest my-react-app -- --template react</code></pre>
<p>This command will create a new folder called <code class="inline-code">my-react-app</code> with all the necessary files and folders to run a React application.</p>
<div class="warning-box">
<strong>⚠️ Note:</strong> Don't forget the <code class="inline-code">--</code> before <code class="inline-code">--template react</code>. This is required!
</div>
<h2>Running Your React Application</h2>
<p>After the installation is complete, navigate to your project folder, install dependencies, and start the development server:</p>
<pre><code>cd my-react-app
npm install
npm run dev</code></pre>
<p>This will start the development server and open your React application in the browser at <code class="inline-code">http://localhost:5173</code> (Vite's default port)</p>
<div class="success-box">
<strong>✨ Success!</strong> If everything went well, you should see the React logo spinning on your screen!
</div>
<h2>Vite Project Structure</h2>
<p>After installation, your Vite project structure will look like this:</p>
<pre><code>my-react-app/
├── node_modules/ (All dependencies)
├── public/ (Static assets)
├── src/
│ ├── App.jsx (Main App component)
│ ├── App.css (App styles)
│ ├── main.jsx (Entry point)
│ ├── index.css (Global styles)
│ └── assets/ (Images, fonts, etc.)
├── index.html (At root, not in public!)
├── package.json (Project configuration)
├── vite.config.js (Vite configuration)
└── README.md</code></pre>
<h3>Important Files</h3>
<ul>
<li><strong>index.html:</strong> The main HTML file at root (KEY DIFFERENCE from CRA!)</li>
<li><strong>src/main.jsx:</strong> The entry point of your React application (.jsx extension)</li>
<li><strong>src/App.jsx:</strong> The main component of your application</li>
<li><strong>vite.config.js:</strong> Vite configuration (port, plugins, etc.)</li>
<li><strong>package.json:</strong> Contains project metadata and dependencies</li>
</ul>
<div class="success-box">
<strong>⚡ Key Differences:</strong>
<ul>
<li><code>index.html</code> is at root (not in public/)</li>
<li>Entry file is <code>main.jsx</code> (not index.js)</li>
<li>Use <code>.jsx</code> extension for files with JSX</li>
<li>Command is <code>npm run dev</code> (not npm start)</li>
<li>Default port is 5173 (not 3000)</li>
</ul>
</div>
<h2>Understanding main.jsx</h2>
<p>The <code class="inline-code">main.jsx</code> file is the entry point of your Vite React application:</p>
<pre><code><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span>
<span class="keyword">import</span> ReactDOM <span class="keyword">from</span> <span class="string">'react-dom/client'</span>
<span class="keyword">import</span> App <span class="keyword">from</span> <span class="string">'./App.jsx'</span>
<span class="keyword">import</span> <span class="string">'./index.css'</span>
ReactDOM.<span class="function">createRoot</span>(document.<span class="function">getElementById</span>(<span class="string">'root'</span>)).<span class="function">render</span>(
<React.StrictMode>
<App />
</React.StrictMode>,
)</code></pre>
<p>Let's break this down:</p>
<ul>
<li>We import React and ReactDOM libraries</li>
<li>We import our main App component (with .jsx extension)</li>
<li>We import global CSS</li>
<li>We create a root and render our App in one statement</li>
</ul>
<h2>Understanding App.jsx</h2>
<p>The <code class="inline-code">App.jsx</code> file contains your main App component:</p>
<pre><code><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span>
<span class="keyword">import</span> <span class="string">'./App.css'</span>
<span class="keyword">function</span> <span class="function">App</span>() {
<span class="keyword">return</span> (
<div className=<span class="string">"App"</span>>
<header className=<span class="string">"App-header"</span>>
<h1>Welcome to React with Vite!</h1>
<p>Edit src/App.jsx and save to see changes instantly!</p>
</header>
</div>
)
}
<span class="keyword">export default</span> App</code></pre>
<h2>Modifying Your First React App</h2>
<p>Let's modify the App component to display a simple message:</p>
<pre><code><span class="keyword">function</span> <span class="function">App</span>() {
<span class="keyword">return</span> (
<div>
<h1>Hello, React!</h1>
<p>This is my first React application.</p>
</div>
);
}
<span class="keyword">export default</span> App;</code></pre>
<p>Save the file, and the browser will automatically reload with your changes!</p>
<div class="success-box">
<strong>🎉 Hot Module Replacement (HMR):</strong> Vite includes blazing-fast HMR, which means your changes will appear instantly in the browser without a full page refresh! This is one of Vite's killer features.
</div>
<h2>Available Vite Scripts</h2>
<p>In your Vite project directory, you can run these commands:</p>
<ul>
<li><code class="inline-code">npm run dev</code> - Runs the app in development mode (⚡ Fast!)</li>
<li><code class="inline-code">npm run build</code> - Builds the app for production</li>
<li><code class="inline-code">npm run preview</code> - Preview the production build locally</li>
<li><code class="inline-code">npm run lint</code> - Run ESLint to check code quality (if configured)</li>
</ul>
<div class="info-box">
<strong>⚡ Vite vs Create React App:</strong>
<ul>
<li><strong>Faster:</strong> Instant server start vs 20-30 seconds</li>
<li><strong>Simpler:</strong> Cleaner project structure</li>
<li><strong>Modern:</strong> ES modules, no bundling in dev</li>
<li><strong>Flexible:</strong> Easy to configure via vite.config.js</li>
</ul>
</div>
<h2>What's Next?</h2>
<p>Now that you have your React development environment set up and running, you're ready to learn about JSX - the syntax that allows you to write HTML in JavaScript!</p>
</div>
<div class="navigation">
<a href="01-introduction.html" class="nav-button">← Previous: Introduction</a>
<a href="index.html" class="home-button">🏠 Home</a>
<a href="03-jsx.html" class="nav-button">Next: React JSX →</a>
</div>
</div>
</body>
</html>
In Tutorial.zip
01-introduction.html6 kB02-getting-started.html9 kB03-jsx.html10 kB04-components.html10 kB05-props.html11 kB06-state.html14 kB07-hooks.html15 kB08-events.html15 kB09-forms.html17 kB10-router.html9 kB11-styling.html11 kB12-useeffect.html11 kB13-usecontext.html13 kB14-useref.html13 kB15-custom-hooks.html19 kBindex.html5 kBstyles.css4 kB