React
Setting Up React Environment
Configure development tools and create your first React project with modern build systems
React development requires specific tools. Unlike writing HTML files and opening them in browsers, React code needs compilation. Components written in JSX must transform into regular JavaScript before browsers can understand them. Think of it like cooking with a recipe written in another language. You need a translator (compiler) to convert the instructions into something you understand. That translator, plus your kitchen tools, makes up your development environment.Node.js: The Foundation
Every React project starts with Node.js. Not because React runs on servers (though it can), but because React's build tools run on Node.js. You're installing a JavaScript runtime that powers your development workflow. Download Node.js from nodejs.org. The LTS version works perfectly. Once installed, open your terminal and verify:// Check Node.js version
node --version // Should show v18.x.x or higher
npm --version // Should show 9.x.x or higherCreate React App vs Modern Alternatives
For years, Create React App (CRA) was the standard. But the React team now recommends modern alternatives that start faster and build optimized code. Here are your options:Creating Your First React Project
Open your terminal and navigate to where you want to create projects. Run this command to create a new React project:// Create new React project with Vite
npm create vite@latest dataflow-dashboard -- --template react
// Navigate to project folder
cd dataflow-dashboard
// Install dependencies
npm install
// Start development server
npm run devVite created a complete React project with all necessary files and configurations. The development server started on localhost:5173 with hot module replacement enabled. Try this: Open the URL in your browser to see your running React app.
Understanding the Project Structure
Open the project in VS Code or your preferred editor. Vite creates a clean folder structure:// DataFlow project structure
dataflow-dashboard/
├── public/ // Static files (favicon, images)
├── src/ // React source code
│ ├── App.jsx // Main App component
│ ├── main.jsx // Entry point
│ └── index.css // Global styles
├── package.json // Project dependencies
└── vite.config.js // Build configurationsrc folder contains your React components. The public folder holds static assets. The package.json file lists dependencies and scripts.
Look inside src/App.jsx. This file contains your main component. Notice the .jsx extension - that tells tools this file contains JSX syntax.
The main.jsx file connects your React app to the HTML page. It finds the element with id="root" in public/index.html and renders your App component there.
Essential Development Tools
React development flows smoother with the right tools. Here are the essentials that professional React teams use daily:React Developer Tools - Debug components, inspect props and state, profile performance
Redux DevTools - Track state changes when you add Redux later
| Extension | Purpose | Key Feature |
|---|---|---|
| ES7+ React/Redux | Code snippets | Type 'rafce' → full component |
| Auto Rename Tag | JSX editing | Change opening tag → closing updates |
| Prettier | Code formatting | Auto-format on save |
| ESLint | Code quality | Catches common mistakes |
Package Management Basics
React projects depend on external packages. The DataFlow dashboard will use packages for charts, date handling, and UI components. Understanding package management prevents headaches later. Thepackage.json file tracks dependencies. When you run npm install, NPM downloads all listed packages into node_modules.
// Add packages to DataFlow project
npm install react-router-dom // Client-side routing
npm install recharts // Charts for dashboard
npm install date-fns // Date utilities
// Development dependencies
npm install --save-dev tailwindcss // CSS frameworknode_modules folder contains thousands of files. Never edit files there directly - your changes disappear when packages update. Never commit node_modules to Git either. Other developers run npm install to recreate it.
Environment Variables and Configuration
DataFlow will connect to APIs and external services. API keys and configuration values belong in environment variables, not hardcoded in components. Vite handles environment variables cleanly. Create a.env file in your project root:
// .env file for DataFlow dashboard
VITE_API_URL=https://api.dataflow.com
VITE_ANALYTICS_KEY=your-analytics-key-here
VITE_APP_NAME=DataFlow Dashboard
// In your React components
const apiUrl = import.meta.env.VITE_API_URL;
const appName = import.meta.env.VITE_APP_NAME;Environment variables keep sensitive data out of your source code. Vite requires the VITE_ prefix to expose variables to your React app. This prevents accidentally leaking server-side secrets to browsers. Try this: Add different environment files for development and production.
.env files. Create .env.local for secrets that shouldn't get committed to Git. The VITE_ prefix makes variables available in your React components.
Environment variables with VITE_ prefix become visible in browsers. Never put secret API keys or passwords in VITE_ variables. Use them for public configuration only.
Development vs Production Builds
Your development server runs unoptimized code for speed. Production builds optimize everything for performance. The difference matters when deploying DataFlow to users.// Development server (fast rebuilds, debugging)
npm run dev
// Production build (optimized, minified)
npm run build
// Preview production build locally
npm run previewnpm run build creates a dist folder with optimized files. Those files get deployed to hosting services like Vercel, Netlify, or traditional web servers.
Git and Version Control Setup
Track DataFlow's development with Git from day one. Vite creates a.gitignore file that excludes node_modules and build artifacts automatically.
// Initialize Git repository
git init
git add .
git commit -m "Initial DataFlow dashboard setup"
// Connect to GitHub (optional)
git remote add origin https://github.com/yourusername/dataflow-dashboard
git push -u origin main.gitignore file prevents committing unnecessary files. Environment files with secrets get ignored too. Only source code, configuration, and documentation get tracked.
Professional React teams commit early and often. Each feature gets its own branch. Pull requests ensure code reviews before merging. GitHub Actions can automatically deploy when you push to main.
Quiz
1. The DataFlow team wants to create a new React project using Vite. Which command creates a React project called "my-app"?
2. You're adding an API endpoint URL to the DataFlow dashboard's environment variables. What prefix must Vite environment variables have to be accessible in React components?
3. A developer wants to share the DataFlow project with teammates. What's the correct approach for the node_modules folder?
Up Next: JSX Basics
Write your first JSX components and understand how React transforms them into interactive elements.