JavaScript and React course Β· Module 1: React Basics
Environment setup
In this lesson6
Preparing for a journey through the React universe, we need a suitable spaceship to take us on this fascinating adventure. That ship will be our development environment, which we must properly configure so our journey goes smoothly.
Let's start with the problem. The browser does not understand the JSX syntax you saw in components. It also doesn't know how to combine dozens of files into one fast application. Someone has to translate and bundle our code before it reaches the user. That someone is the development tooling, and preparing it is what this lesson is about. JSX is translated by a compiler such as Babel: it first parses the code into a syntax tree (AST, Abstract Syntax Tree), then transforms that tree with plugins and presets, and finally generates plain JavaScript that browsers understand.
Why is environment setup important?
A well-configured development environment is the foundation for effective work with React. It allows you to:
- Quickly create and test components
- Automatically refresh the page after making changes (Hot Reloading)
- Detect errors at an early stage
- Optimize code before production deployment
About the second point: in Vite this mechanism is called HMR (Hot Module Replacement), and in React projects it works as Fast Refresh. When you save a file, only the edited component changes, and the state of the rest of the application is preserved.
Imagine trying to build an advanced spaceship without the right tools - it would be extremely difficult and time-consuming. The same goes for creating React applications without a proper environment.
Prerequisites
Before we start configuring our React environment, let's make sure we have all the necessary tools installed:
- Code editor - We recommend Visual Studio Code, which offers excellent React support through many extensions
- Web browser - Preferably Chrome or Firefox with React Developer Tools installed
- Terminal - The built-in terminal in your operating system or one integrated with the code editor
Once we have these basic tools, we can proceed to configure the React environment.
Node.js - the engine in the engine room
There is a fourth and most important element: Node.js, an environment that runs JavaScript outside the browser. React itself runs in the user's browser, so Node.js is not part of the finished application. We need it on our computer to run the development tools: the preview server, the JSX compiler and the production build process. Node.js comes with the npm package manager, which we will use to download React and Vite.
After installation (we will go through it step by step in the next lesson) you can check in the terminal that the engine is running:
node -v
npm -vEach command should print a version number. If the terminal says it doesn't know the command, Node.js is not installed yet or the terminal needs to be restarted. Nothing in your project changes here, it is just a pre-launch check.
Choosing a configuration approach
There are two main approaches to React environment configuration:
- Build tools from scratch - Manually configuring Webpack, Babel, and other tools
- Ready-made solutions - Using tools like Vite, Next.js, or Remix
For beginners, we definitely recommend the second approach, as it allows you to focus on learning React rather than configuration details.
It is worth knowing exactly what the react.dev documentation says today. For new applications it recommends starting with a framework, such as Next.js, React Router (version 7, into which Remix development was moved) or Expo for mobile apps. If you build an app without a framework, the documentation points to the build tools Vite, Parcel and Rsbuild.
In our course, we'll be using Vite - a modern, fast build tool that the React documentation lists among the recommended ways to create a project without a framework. I choose it on purpose: it doesn't add its own rules for routing or data fetching, so you see plain React. Create React App (CRA) has been deprecated and is no longer maintained - the React team announced this in February 2025, so if you come across a tutorial using create-react-app, treat it as archival.
What you get in a Vite project
A project created by Vite has ready-made scripts in its package.json file. They are what runs the tools powered by Node.js:
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}The npm run dev command starts the preview server with Fast Refresh, npm run build creates an optimized production version in the dist folder, and npm run preview lets you view it locally. Your component code stays the same in all three cases, only the way the tools prepare it changes.
A first look through React Developer Tools
The React Developer Tools extension shows you the component tree of a running application. In it you will see an important React principle: one-way data flow. Data flows from a parent component to a child through props, never the other way round:
function Bridge() {
return <FuelGauge fuel={80} />;
}Here Bridge passes the fuel value down to FuelGauge. The child can display it but cannot change it in the parent - in DevTools you will see it as a prop of the FuelGauge component. You will learn more about this flow when we start building our own components.
My recommendation: install VS Code, the current LTS version of Node.js and React Developer Tools right away, and create projects with Vite. This set is enough for the whole course. In the next lesson we will go step by step through installing Node.js and npm.
In the sandbox below you can expand the cards of different tools and compare their pros and cons.
Remember: Node.js is the engine in the engine room that powers the development tools, and Vite is the ship on which you comfortably launch with React.
Code for this lesson: App.jsx
import React from 'react';
// Component demonstrating various tools
function DevelopmentTool({ name, logo, type, description, pros, cons, difficulty }) {
const [isExpanded, setIsExpanded] = React.useState(false);
const getDifficultyColor = (level) => {
switch(level) {
case 'Easy': return '#4caf50';
case 'Medium': return '#ff9800';
case 'Hard': return '#f44336';
default: return '#666';
}
};
const getTypeColor = (toolType) => {
switch(toolType) {
case 'CLI Tool': return '#2196f3';
case 'Build Tool': return '#9c27b0';
case 'Framework': return '#ff5722';
default: return '#666';
}
};
return (
<div style={{
border: '2px solid #e0e0e0',
borderRadius: '12px',
margin: '15px 0',
overflow: 'hidden',
transition: 'all 0.3s ease',
boxShadow: isExpanded ? '0 8px 25px rgba(0,0,0,0.15)' : '0 2px 8px rgba(0,0,0,0.1)'
}}>
<div
style={{
padding: '20px',
backgroundColor: 'white',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between'
}}
onClick={() => setIsExpanded(!isExpanded)}
>
<div style={{ display: 'flex', alignItems: 'center', gap: '15px' }}>
<div style={{ fontSize: '48px' }}>{logo}</div>
<div>
<h3 style={{ margin: '0 0 5px 0', color: '#333' }}>{name}</h3>
<div style={{ display: 'flex', gap: '10px' }}>
<span style={{
padding: '4px 12px',
backgroundColor: getTypeColor(type),
color: 'white',
borderRadius: '15px',
fontSize: '12px',
fontWeight: 'bold'
}}>
{type}
</span>
<span style={{
padding: '4px 12px',
backgroundColor: getDifficultyColor(difficulty),
color: 'white',
borderRadius: '15px',
fontSize: '12px',
fontWeight: 'bold'
}}>
{difficulty}
</span>
</div>
</div>
</div>
<div style={{
fontSize: '20px',
color: '#666',
transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
transition: 'transform 0.3s ease'
}}>
βΌ
</div>
</div>
{isExpanded && (
<div style={{
padding: '20px',
backgroundColor: '#f8f9fa',
borderTop: '1px solid #e0e0e0'
}}>
<p style={{
marginBottom: '20px',
color: '#666',
lineHeight: '1.6',
fontSize: '16px'
}}>
{description}
</p>
<div style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr',
gap: '20px'
}}>
<div>
<h4 style={{ color: '#4caf50', marginBottom: '10px' }}>Pros</h4>
<ul style={{ margin: 0, paddingLeft: '20px', color: '#333' }}>
{pros.map((pro, index) => (
<li key={index} style={{ marginBottom: '5px' }}>{pro}</li>
))}
</ul>
</div>
<div>
<h4 style={{ color: '#f44336', marginBottom: '10px' }}>Cons</h4>
<ul style={{ margin: 0, paddingLeft: '20px', color: '#333' }}>
{cons.map((con, index) => (
<li key={index} style={{ marginBottom: '5px' }}>{con}</li>
))}
</ul>
</div>
</div>
</div>
)}
</div>
);
}
// Component demonstrating the setup process
function SetupProcess() {
const [currentStep, setCurrentStep] = React.useState(0);
const [selectedTool, setSelectedTool] = React.useState('Vite');
const steps = {
CRA: [
{
title: "Check Node.js",
command: "node --version",
expected: "v20.19.0 or newer",
description: "Make sure you have Node.js installed"
},
{
title: "Create a new project",
command: "npx create-react-app my-app",
expected: "The project will be created",
description: "Create React App will automatically configure everything"
},
{
title: "Navigate to the project",
command: "cd my-app",
expected: "Directory changed",
description: "Enter the folder with the new project"
},
{
title: "Start server",
command: "npm start",
expected: "The app opens at localhost:3000",
description: "Start the development server with hot reloading"
}
],
Vite: [
{
title: "Check Node.js",
command: "node --version",
expected: "v20.19.0 or newer",
description: "Vite requires Node.js 20.19+ or 22.12+"
},
{
title: "Create a project with Vite",
command: "npm create vite@latest my-app -- --template react",
expected: "The Vite project will be created",
description: "Vite is faster and more modern"
},
{
title: "Install dependencies",
command: "cd my-app && npm install",
expected: "Dependencies installed",
description: "Install all required packages"
},
{
title: "Start server",
command: "npm run dev",
expected: "The app opens at localhost:5173",
description: "Vite uses a different port than CRA"
}
]
};
const currentSteps = steps[selectedTool];
const currentStepData = currentSteps[currentStep];
const nextStep = () => {
if (currentStep < currentSteps.length - 1) {
setCurrentStep(currentStep + 1);
}
};
const prevStep = () => {
if (currentStep > 0) {
setCurrentStep(currentStep - 1);
}
};
const resetSteps = () => {
setCurrentStep(0);
};
const changeTool = (tool) => {
setSelectedTool(tool);
setCurrentStep(0);
};
return (
<div style={{
backgroundColor: '#f3e5f5',
padding: '25px',
borderRadius: '12px',
margin: '20px 0'
}}>
<h3 style={{ color: '#7b1fa2', marginBottom: '20px', textAlign: 'center' }}>
Interactive Setup Guide
</h3>
<div style={{
display: 'flex',
justifyContent: 'center',
gap: '10px',
marginBottom: '25px'
}}>
<button
onClick={() => changeTool('CRA')}
style={{
padding: '10px 20px',
backgroundColor: selectedTool === 'CRA' ? '#9c27b0' : 'white',
color: selectedTool === 'CRA' ? 'white' : '#333',
border: '2px solid #9c27b0',
borderRadius: '8px',
cursor: 'pointer',
fontWeight: 'bold'
}}
>
Create React App
</button>
<button
onClick={() => changeTool('Vite')}
style={{
padding: '10px 20px',
backgroundColor: selectedTool === 'Vite' ? '#9c27b0' : 'white',
color: selectedTool === 'Vite' ? 'white' : '#333',
border: '2px solid #9c27b0',
borderRadius: '8px',
cursor: 'pointer',
fontWeight: 'bold'
}}
>
Vite
</button>
</div>
<div style={{
backgroundColor: 'white',
padding: '25px',
borderRadius: '8px',
minHeight: '200px'
}}>
<div style={{
display: 'flex',
alignItems: 'center',
marginBottom: '20px'
}}>
<div style={{
width: '50px',
height: '50px',
backgroundColor: '#9c27b0',
color: 'white',
borderRadius: '50%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontWeight: 'bold',
fontSize: '18px',
marginRight: '15px'
}}>
{currentStep + 1}
</div>
<h4 style={{ margin: 0, color: '#333', fontSize: '1.3rem' }}>
{currentStepData.title}
</h4>
</div>
<p style={{
color: '#666',
marginBottom: '20px',
fontSize: '16px',
lineHeight: '1.5'
}}>
{currentStepData.description}
</p>
<div style={{
backgroundColor: '#1e1e1e',
color: '#00ff00',
padding: '15px',
borderRadius: '6px',
fontFamily: 'Monaco, monospace',
marginBottom: '15px',
fontSize: '14px',
overflow: 'auto'
}}>
<div style={{ marginBottom: '5px', color: '#888' }}>$ {currentStepData.command}</div>
<div style={{ color: '#00ff00' }}>{currentStepData.expected}</div>
</div>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
}}>
<div style={{
display: 'flex',
gap: '10px'
}}>
<button
onClick={prevStep}
disabled={currentStep === 0}
style={{
padding: '8px 16px',
backgroundColor: currentStep === 0 ? '#ccc' : '#666',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: currentStep === 0 ? 'not-allowed' : 'pointer'
}}
>
β Previous
</button>
<button
onClick={nextStep}
disabled={currentStep === currentSteps.length - 1}
style={{
padding: '8px 16px',
backgroundColor: currentStep === currentSteps.length - 1 ? '#ccc' : '#9c27b0',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: currentStep === currentSteps.length - 1 ? 'not-allowed' : 'pointer'
}}
>
Next β
</button>
<button
onClick={resetSteps}
style={{
padding: '8px 16px',
backgroundColor: '#f44336',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: 'pointer'
}}
>
Reset
</button>
</div>
<div style={{ display: 'flex', gap: '5px', alignItems: 'center' }}>
{currentSteps.map((_, index) => (
<div
key={index}
style={{
width: '12px',
height: '12px',
borderRadius: '50%',
backgroundColor: index <= currentStep ? '#9c27b0' : '#ddd',
transition: 'background-color 0.3s'
}}
/>
))}
<span style={{ marginLeft: '10px', color: '#666', fontSize: '14px' }}>
{currentStep + 1} / {currentSteps.length}
</span>
</div>
</div>
</div>
</div>
);
}
// Component for comparing tools
function ToolComparison() {
const tools = [
{
name: 'Create React App',
speed: 70,
ease: 95,
flexibility: 40,
popularity: 90
},
{
name: 'Vite',
speed: 95,
ease: 85,
flexibility: 80,
popularity: 75
},
{
name: 'Next.js',
speed: 85,
ease: 60,
flexibility: 90,
popularity: 85
},
{
name: 'Manual Setup',
speed: 30,
ease: 20,
flexibility: 100,
popularity: 30
}
];
return (
<div style={{
backgroundColor: '#e3f2fd',
padding: '25px',
borderRadius: '12px',
margin: '20px 0'
}}>
<h3 style={{ color: '#1976d2', textAlign: 'center', marginBottom: '25px' }}>
React Setup Tools Comparison
</h3>
<div style={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))',
gap: '20px'
}}>
{tools.map((tool, index) => (
<div key={index} style={{
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
boxShadow: '0 2px 8px rgba(0,0,0,0.1)'
}}>
<h4 style={{ color: '#1976d2', marginBottom: '15px', textAlign: 'center' }}>
{tool.name}
</h4>
<div style={{ marginBottom: '12px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '4px' }}>
<span style={{ fontSize: '14px' }}>Speed</span>
<span style={{ fontSize: '14px' }}>{tool.speed}%</span>
</div>
<div style={{
height: '8px',
backgroundColor: '#e0e0e0',
borderRadius: '4px',
overflow: 'hidden'
}}>
<div style={{
height: '100%',
backgroundColor: '#4caf50',
width: `${tool.speed}%`,
transition: 'width 1s ease'
}}></div>
</div>
</div>
<div style={{ marginBottom: '12px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '4px' }}>
<span style={{ fontSize: '14px' }}>Ease of use</span>
<span style={{ fontSize: '14px' }}>{tool.ease}%</span>
</div>
<div style={{
height: '8px',
backgroundColor: '#e0e0e0',
borderRadius: '4px',
overflow: 'hidden'
}}>
<div style={{
height: '100%',
backgroundColor: '#2196f3',
width: `${tool.ease}%`,
transition: 'width 1s ease'
}}></div>
</div>
</div>
<div style={{ marginBottom: '12px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '4px' }}>
<span style={{ fontSize: '14px' }}>Flexibility</span>
<span style={{ fontSize: '14px' }}>{tool.flexibility}%</span>
</div>
<div style={{
height: '8px',
backgroundColor: '#e0e0e0',
borderRadius: '4px',
overflow: 'hidden'
}}>
<div style={{
height: '100%',
backgroundColor: '#ff9800',
width: `${tool.flexibility}%`,
transition: 'width 1s ease'
}}></div>
</div>
</div>
<div style={{ marginBottom: '12px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '4px' }}>
<span style={{ fontSize: '14px' }}>Popularity</span>
<span style={{ fontSize: '14px' }}>{tool.popularity}%</span>
</div>
<div style={{
height: '8px',
backgroundColor: '#e0e0e0',
borderRadius: '4px',
overflow: 'hidden'
}}>
<div style={{
height: '100%',
backgroundColor: '#9c27b0',
width: `${tool.popularity}%`,
transition: 'width 1s ease'
}}></div>
</div>
</div>
</div>
))}
</div>
</div>
);
}
export default function App() {
return (
<div style={{
fontFamily: 'Arial, sans-serif',
maxWidth: '1000px',
margin: '0 auto',
padding: '20px'
}}>
<header style={{
textAlign: 'center',
marginBottom: '30px',
padding: '25px',
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
color: 'white',
borderRadius: '12px'
}}>
<h1 style={{ margin: '0 0 10px 0', fontSize: '2.2rem' }}>
React Environment Setup
</h1>
<p style={{ margin: 0, fontSize: '1rem', opacity: 0.9 }}>
Everything you need to know about preparing a development environment for React
</p>
</header>
<section style={{ marginBottom: '30px' }}>
<h2 style={{
color: '#333',
borderBottom: '2px solid #667eea',
paddingBottom: '10px',
marginBottom: '20px'
}}>
Available Tools
</h2>
<DevelopmentTool
name="Create React App"
logo="β"
type="CLI Tool"
difficulty="Easy"
description="The former official React tool, deprecated in February 2025 and no longer maintained. You will meet it in older tutorials."
pros={[
"Zero configuration to start",
"Official React support",
"Built-in hot reloading",
"Production optimization",
"Testing support"
]}
cons={[
"Less flexibility",
"Larger bundle size",
"Hard to customize",
"Can be overkill for simple projects"
]}
/>
<DevelopmentTool
name="Vite"
logo="β―"
type="Build Tool"
difficulty="Medium"
description="Modern build tool with native ES modules support. Lightning fast."
pros={[
"Very fast development server",
"Native ES modules",
"Smaller bundle size",
"Better hot reloading",
"TypeScript support out-of-the-box"
]}
cons={[
"Younger technology",
"Smaller plugin ecosystem",
"May require additional configuration",
"Fewer ready-made templates"
]}
/>
<DevelopmentTool
name="Next.js"
logo="β²"
type="Framework"
difficulty="Medium"
description="Full-stack React framework with server-side rendering, routing and many other features."
pros={[
"Server-side rendering",
"Automatic routing",
"Built-in API routes",
"Image optimization",
"Great performance"
]}
cons={[
"Can be overkill for simple SPAs",
"Steeper learning curve",
"Opinionated structure",
"Greater complexity"
]}
/>
<DevelopmentTool
name="Manual Setup"
logo="β"
type="Build Tool"
difficulty="Hard"
description="Manual configuration of Webpack, Babel and other tools. Maximum control, but requires knowledge."
pros={[
"Full control over configuration",
"Ability to customize for specific needs",
"Deeper understanding of tools",
"Optimal performance"
]}
cons={[
"Very time-consuming",
"Requires advanced knowledge",
"Complicated to maintain",
"Easy to make mistakes"
]}
/>
</section>
<SetupProcess />
<ToolComparison />
<div style={{
backgroundColor: '#e8f5e8',
padding: '25px',
borderRadius: '12px',
marginTop: '30px'
}}>
<h3 style={{ color: '#2e7d32', textAlign: 'center', marginBottom: '20px' }}>
Which Tool to Choose?
</h3>
<div style={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))',
gap: '20px'
}}>
<div style={{
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
textAlign: 'center'
}}>
<h4 style={{ color: '#2196f3', marginBottom: '10px' }}>Beginners</h4>
<p style={{ margin: 0, color: '#666' }}>
<strong>Vite</strong><br/>
Quick start, recommended in this course
</p>
</div>
<div style={{
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
textAlign: 'center'
}}>
<h4 style={{ color: '#2196f3', marginBottom: '10px' }}>Performance</h4>
<p style={{ margin: 0, color: '#666' }}>
<strong>Vite</strong><br/>
Development speed
</p>
</div>
<div style={{
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
textAlign: 'center'
}}>
<h4 style={{ color: '#2196f3', marginBottom: '10px' }}>Full-Stack</h4>
<p style={{ margin: 0, color: '#666' }}>
<strong>Next.js</strong><br/>
SSR, routing, API
</p>
</div>
<div style={{
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
textAlign: 'center'
}}>
<h4 style={{ color: '#2196f3', marginBottom: '10px' }}>Experts</h4>
<p style={{ margin: 0, color: '#666' }}>
<strong>Manual Setup</strong><br/>
Full control
</p>
</div>
</div>
</div>
</div>
);
}Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. Why is Node.js needed for React development?
2. How does one-way data flow work in React?