Build Tools: Create React App vs Vite
Build tools handle the complex setup needed for modern React development: JSX compilation, hot reloading, bundling, and optimization. Here are the two most popular choices.
๐ฆ What is CRA?
Official React toolchain that sets up a modern web app with zero configuration.
โ Pros:
- Official React team support
- Zero configuration needed
- Battle-tested and stable
- Great for beginners
- Excellent documentation
โ Cons:
- Slower development server
- Larger bundle sizes
- Less flexible configuration
- Longer build times
# Create new React app
npx create-react-app my-app
cd my-app
# Start development server
npm start
# Build for production
npm run build
# Run tests
npm test
# Eject (reveals configuration)
npm run eject
โก What is Vite?
Next-generation build tool that's significantly faster than traditional bundlers.
โ Pros:
- Lightning-fast development server
- Instant hot module replacement
- Smaller bundle sizes
- Modern ES modules support
- Highly configurable
โ Cons:
- Less mature ecosystem
- May require more configuration
- Learning curve for advanced features
# Create new React app with Vite
npm create vite@latest my-app -- --template react
cd my-app
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
React Developer Tools
The React Developer Tools are essential browser extensions that help you inspect React component hierarchies, examine props and state, and debug performance issues.
๐ Installation and Features
๐ฅ Installation
- Chrome: Install from Chrome Web Store
- Firefox: Install from Firefox Add-ons
- Edge: Install from Microsoft Edge Add-ons
- Standalone: Available as desktop app
๐งฉ Components Tab
- View component hierarchy
- Inspect props and state
- Edit props and state live
- See component source code
- Track component updates
๐ Profiler Tab
- Measure component performance
- Identify slow components
- Track render times
- Find unnecessary re-renders
- Analyze component interactions
โ๏ธ Advanced Features
- Component highlighting
- Search and filter components
- Hook inspection
- Context value viewing
- Suspense boundary tracking
// Add displayName to components for better debugging
function UserProfile({ user }) {
return (
<div>
<h1>{user.name}</h1>
<p>{user.email}</p>
</div>
);
}
UserProfile.displayName = 'UserProfile';
// Use React.memo with a name for optimization tracking
const MemoizedComponent = React.memo(function ExpensiveComponent({ data }) {
// Expensive computation here
return <div>{/* rendered content */}</div>;
});
// Add debugging hooks for development
function useDebugValue(value, formatFn) {
React.useDebugValue(value, formatFn);
}
function useUser(userId) {
const [user, setUser] = useState(null);
// This will show in DevTools
useDebugValue(user, user => user?.name ?? 'Loading...');
useEffect(() => {
// fetch user data
}, [userId]);
return user;
}
Code Editors and Extensions
๐ Visual Studio Code
Most popular editor for React development with excellent JSX support.
๐ Essential Extensions:
- ES7+ React/Redux/React-Native snippets - Code snippets
- Prettier - Code formatting
- ESLint - Code linting
- Auto Rename Tag - Sync HTML/JSX tags
- Bracket Pair Colorizer - Visual bracket matching
- GitLens - Enhanced Git capabilities
- Thunder Client - API testing
โ๏ธ Other Editors
WebStorm:
- Built-in React support
- Advanced refactoring tools
- Integrated debugging
- Paid but feature-rich
Atom (Sunset):
- Good React packages available
- Highly customizable
- Development discontinued
Vim/Neovim:
- CoC.nvim for language server
- vim-jsx-pretty for JSX syntax
- High performance
Package Managers
๐ฆ Default Choice
Comes with Node.js, most widely used and supported.
# Install dependencies
npm install
# Add a package
npm install react-router-dom
# Add dev dependency
npm install --save-dev @types/react
# Remove package
npm uninstall package-name
# Update packages
npm update
# Run scripts
npm start
npm run build
๐ Faster Alternative
Facebook's package manager with improved performance and features.
# Install dependencies
yarn
# Add a package
yarn add react-router-dom
# Add dev dependency
yarn add --dev @types/react
# Remove package
yarn remove package-name
# Update packages
yarn upgrade
# Run scripts
yarn start
yarn build
๐ Package Manager Comparison
| Feature | npm | Yarn | pnpm |
|---|---|---|---|
| Installation Speed | Good | Fast | Fastest |
| Disk Space | Standard | Standard | Efficient |
| Lock File | package-lock.json | yarn.lock | pnpm-lock.yaml |
| Workspaces | Yes | Yes | Yes |
Testing Tools
๐งช Jest
JavaScript testing framework with built-in assertions, mocking, and code coverage.
// Button.test.js
import { render, screen, fireEvent } from '@testing-library/react';
import Button from './Button';
describe('Button Component', () => {
test('renders button with text', () => {
render(<Button>Click me</Button>);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
test('calls onClick when clicked', () => {
const handleClick = jest.fn();
render(<Button onClick={handleClick}>Click me</Button>);
fireEvent.click(screen.getByText('Click me'));
expect(handleClick).toHaveBeenCalledTimes(1);
});
});
๐ฌ React Testing Library
Testing utility that encourages testing behavior rather than implementation.
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import UserProfile from './UserProfile';
test('displays user information after loading', async () => {
render(<UserProfile userId="123" />);
// Wait for async data to load
await waitFor(() => {
expect(screen.getByText('John Doe')).toBeInTheDocument();
});
// Test user interaction
const user = userEvent.setup();
await user.click(screen.getByText('Edit Profile'));
expect(screen.getByRole('textbox', { name: /name/i })).toBeInTheDocument();
});
Development Server and Debugging
๐ฅ Hot Module Replacement
Updates code in the browser without losing application state.
// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
open: true, // Auto-open browser
hmr: {
overlay: true // Show errors in browser overlay
}
}
})
๐ Browser DevTools
Built-in browser debugging capabilities for React apps.
- Console: View logs and errors
- Sources: Set breakpoints in code
- Network: Monitor API calls
- Performance: Profile component rendering
- Application: Inspect localStorage/sessionStorage
๐ฑ Mobile Development
Tools for testing React apps on mobile devices.
- Chrome DevTools Device Mode: Simulate mobile devices
- BrowserStack: Test on real devices
- Expo: For React Native development
- ngrok: Expose local dev server to internet
โก Performance Tools
Monitor and optimize React application performance.
- Lighthouse: Web performance audits
- Webpack Bundle Analyzer: Analyze bundle size
- React DevTools Profiler: Component performance
- Web Vitals: Core web performance metrics
Recommended Tool Stack
๐ For Beginners
Essential Setup
- Build Tool: Create React App
- Editor: VS Code
- Package Manager: npm
- Browser: Chrome with React DevTools
- Version Control: Git + GitHub
VS Code Extensions
- ES7+ React/Redux snippets
- Prettier
- ESLint
- Auto Rename Tag
- GitLens
โก For Advanced Users
Performance-Focused
- Build Tool: Vite
- Package Manager: pnpm
- Testing: Vitest + Testing Library
- Bundler Analysis: Bundle Analyzer
- Performance: Lighthouse CI
Team Development
- Code Quality: Husky + lint-staged
- Documentation: Storybook
- CI/CD: GitHub Actions
- Deployment: Vercel/Netlify
- Monitoring: Sentry
What's Next?
You now know the essential tools for React development. These tools will make you more productive and help you build better applications. Next, explore Next.js for full-stack React development.
๐ Continue Learning
- Next.js - Full-stack React framework with amazing DX
- Popular Libraries - UI libraries and ecosystem tools
- Transition Guide - Complete migration strategies
- Learning Path - Structured approach to mastering React