React Installation
Overview
This chapter will detail how to set up a React development environment, including Node.js installation, development tool configuration, creating your first React project, and more. We will learn multiple ways to create React projects, as well as necessary development tool installations.
🛠️ Prerequisites
Required Software
Node.js and npm
Recommended Configuration:
- Node.js 18.0+ or 20.0+ (LTS version)
- npm 8.0+ or yarn 1.22+
- Modern browsers (Chrome, Firefox, Safari, Edge)
Optional Tools
- Git: Version control
- VS Code: Recommended code editor
- Chrome DevTools: Debugging tools
📥 Node.js Installation
Windows Systems
macOS Systems
Linux Systems
Verifying Installation
🚀 Creating React Projects
Method 1: Create React App (Recommended for Beginners)
Installation and project creation:
Project Structure:
Method 2: Vite (Recommended for Production Projects)
Creating a project:
Vite Project Structure:
Method 3: Next.js (Full-stack React Framework)
Creating a project:
Method 4: Manual Setup
Creating basic structure:
Creating basic files:
index.html:
src/main.jsx:
src/App.jsx:
vite.config.js:
🔧 Development Tool Configuration
VS Code Extensions Recommendations
Required Extensions:
React-related Extensions:
- ES7+ React/Redux/React-Native snippets: Code snippets
- Bracket Pair Colorizer 2: Bracket pairing colorization
- Auto Rename Tag: Auto rename tags
- GitLens: Git enhancement
- Thunder Client: API testing
Code Formatting Configuration
Prettier Configuration (.prettierrc):
ESLint Configuration (.eslintrc.js):
🌐 Browser Development Tools
React Developer Tools
Installing browser extensions:
- Chrome: React Developer Tools
- Firefox: React Developer Tools
- Edge: Install from Chrome Web Store
Features:
📦 Package Manager Comparison
npm vs yarn vs pnpm
npm (Default):
Yarn:
pnpm (Recommended):
Performance Comparison:
🛠️ Project Template Selection
Create React App Use Cases
Advantages:
- Zero configuration to start
- Good community support
- Good for learning
- Built-in testing environment
Disadvantages:
- Slow build speed
- Large bundle size
- Less flexible configuration
Vite Use Cases
Advantages:
- Extremely fast startup
- Fast hot reload
- Fast build speed
- Flexible configuration
Disadvantages:
- Relatively new
- Smaller plugin ecosystem
Next.js Use Cases
Advantages:
- Server-side rendering
- Static site generation
- API routes
- File system routing
Use Cases:
- SEO-important websites
- Need server-side rendering
- Full-stack application development
🔍 Common Problem Solutions
Node.js Version Management
Using nvm (Recommended):
Network Problem Solutions
Configuring npm registry:
Using cnpm:
Permission Problem Solutions
Global package permission issues:
🎯 Verifying Installation
Creating a Test Project
Checking Key Features
Performance Check
📝 Chapter Summary
Through this chapter, you should have mastered:
Key Takeaways
- ✅ Node.js and npm installation and configuration
- ✅ Multiple React project creation methods
- ✅ Development tools and extension configuration
- ✅ Browser development tools usage
- ✅ Package manager selection and usage
- ✅ Common problem solutions
Best Practices
- Use LTS version of Node.js: Stable and reliable
- Choose appropriate project template: Based on requirements
- Configure code formatting tools: Maintain code consistency
- Install necessary development tools: Improve development efficiency
- Regularly update dependencies: Maintain security and performance
Next Steps
- Learn project structure and file organization
- Understand how development server works
- Master build and deployment process
Continue Learning: Next Chapter - React Quick Start