Comprehensive guide for building scalable React applications with modern patterns, performance optimization, and best practices
This repository contains a complete set of development guides for modern React applications, focusing on JavaScript patterns, performance optimization, and maintainable code architecture. Built for teams transitioning from traditional setups to modern React development.
Guide | Description | Key Topics |
---|---|---|
JavaScript Guide | Modern JavaScript patterns and best practices | ES2024, async/await, modules, error handling |
React Guide | React 19+ patterns and component architecture | Hooks, components, state management, performance |
SOLID Principles | SOLID principles applied to React development | Component design, maintainability, architecture |
Custom Hooks Guide | Hook design patterns and best practices | Hook composition, testing, performance |
Guide | Description | Key Topics |
---|---|---|
File Organization | Project structure and naming conventions | Folder structure, imports, code splitting |
ESLint Configuration | Modern ESLint setup extending Airbnb | Rules, IDE integration, CI/CD |
Testing Guide | Comprehensive testing with Vitest | Component testing, hooks, integration |
Guide | Description | Key Topics |
---|---|---|
Performance Guide | React performance optimization techniques | Bundle optimization, memory management, monitoring |
Migration Guide | Migrating from legacy patterns and Airbnb config | Step-by-step migration, code transformation |
# Create new React project with Vite
npm create vite@latest my-react-app -- --template react
cd my-react-app
# Install dependencies
npm install
# Install development dependencies
npm install --save-dev eslint vitest @testing-library/react
Follow the ESLint Configuration Guide to set up modern linting rules:
# Install ESLint dependencies
npm install --save-dev eslint-config-airbnb eslint-plugin-react-hooks
npm install --save-dev eslint-plugin-unicorn eslint-plugin-sonarjs
Follow the Testing Guide to configure Vitest:
# Install testing dependencies
npm install --save-dev vitest @testing-library/jest-dom @testing-library/user-event
Use the File Organization Guide to structure your project:
src/
βββ components/ # Reusable components
βββ pages/ # Page components
βββ lib/ # Utilities and helpers
βββ services/ # API and external services
βββ assets/ # Static assets
- Functional Components Only - Use hooks for all state and side effects
- Single Responsibility - Each component has one clear purpose
- Composition over Inheritance - Build complex UIs through composition
- Props Interface Design - Clear, documented prop interfaces
- Bundle Optimization - Code splitting and tree shaking
- React Optimization - memo, useMemo, useCallback where beneficial
- Loading Strategies - Progressive enhancement and lazy loading
- Memory Management - Proper cleanup and optimization
- Modern Tooling - Vite, Vitest, ESLint with modern rules
- Type Safety - PropTypes and careful data handling
- Testing Strategy - Comprehensive testing at all levels
- Documentation - Clear documentation and examples
// Follow React Guide patterns
import { useState, useCallback } from 'react';
import PropTypes from 'prop-types';
const UserCard = ({ user, onEdit, onDelete }) => {
const [isExpanded, setIsExpanded] = useState(false);
const handleEdit = useCallback(() => {
onEdit(user);
}, [user, onEdit]);
return (
<div className="user-card">
<UserAvatar user={user} />
<UserInfo user={user} expanded={isExpanded} />
<UserActions onEdit={handleEdit} onDelete={onDelete} />
</div>
);
};
UserCard.propTypes = {
user: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
email: PropTypes.string.isRequired
}).isRequired,
onEdit: PropTypes.func,
onDelete: PropTypes.func
};
export default UserCard;
// Follow Custom Hooks Guide patterns
const useUserData = (userId) => {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
let cancelled = false;
const fetchUser = async () => {
try {
setLoading(true);
const userData = await getUserById(userId);
if (!cancelled) {
setUser(userData);
}
} catch (err) {
if (!cancelled) {
setError(err);
}
} finally {
if (!cancelled) {
setLoading(false);
}
}
};
if (userId) {
fetchUser();
}
return () => {
cancelled = true;
};
}, [userId]);
return { user, loading, error };
};
// Follow Testing Guide patterns
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, it, expect, vi } from 'vitest';
import UserCard from './UserCard';
describe('UserCard', () => {
const mockUser = {
id: '1',
name: 'John Doe',
email: '[email protected]'
};
it('renders user information correctly', () => {
render(<UserCard user={mockUser} />);
expect(screen.getByText('John Doe')).toBeInTheDocument();
expect(screen.getByText('[email protected]')).toBeInTheDocument();
});
it('calls onEdit when edit button is clicked', async () => {
const user = userEvent.setup();
const onEdit = vi.fn();
render(<UserCard user={mockUser} onEdit={onEdit} />);
await user.click(screen.getByRole('button', { name: /edit/i }));
expect(onEdit).toHaveBeenCalledWith(mockUser);
});
});
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest run --coverage",
"lint": "eslint src --ext .js,.jsx --max-warnings 0",
"lint:fix": "eslint src --ext .js,.jsx --fix",
"type-check": "tsc --noEmit"
}
}
# React ecosystem
npm install react react-dom react-router-dom
# State management (choose based on needs)
npm install @tanstack/react-query # For server state
npm install @reduxjs/toolkit react-redux # For complex client state
# UI and utilities
npm install axios date-fns
# Build tools
npm install --save-dev vite @vitejs/plugin-react
# Linting and formatting
npm install --save-dev eslint eslint-config-airbnb
npm install --save-dev eslint-plugin-react eslint-plugin-react-hooks
npm install --save-dev prettier
# Testing
npm install --save-dev vitest @testing-library/react
npm install --save-dev @testing-library/jest-dom @testing-library/user-event
npm install --save-dev jsdom
# Analyze bundle size
npm run build
npx vite-bundle-analyzer dist
# Monitor bundle size
npm install --save-dev size-limit
// Route-based splitting
const Dashboard = lazy(() => import('./pages/Dashboard'));
const UserProfile = lazy(() => import('./pages/UserProfile'));
// Feature-based splitting
const AdminPanel = lazy(() => import('./features/admin/AdminPanel'));
// Core Web Vitals
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';
getCLS(console.log);
getFID(console.log);
getFCP(console.log);
getLCP(console.log);
getTTFB(console.log);
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": ["javascript", "javascriptreact"]
}
- ESLint
- Prettier - Code formatter
- ES7+ React/Redux/React-Native snippets
- Auto Rename Tag
- Bracket Pair Colorizer
- Update ESLint Config - Follow ESLint Configuration Guide
- Convert Class Components - Use Migration Guide
- Modernize Patterns - Apply React Guide patterns
- Optimize Performance - Implement Performance Guide techniques
- Migrate to Vite - Follow build tool migration in Migration Guide
- Update Testing - Switch from Jest to Vitest
- Reorganize Structure - Apply File Organization Guide
- Optimize Bundle - Implement code splitting and optimization
- Follow Existing Structure - Use established guide formats
- Provide Examples - Include practical, real-world examples
- Test Thoroughly - Ensure all examples work as expected
- Document Rationale - Explain why patterns are recommended
- Keep Current - Update for latest React and ecosystem changes
- Maintain Consistency - Follow established conventions
- Add Migration Notes - Help teams transition smoothly
- Test Examples - Verify all code examples work
- React Patterns
- JavaScript Info
- Web.dev - Performance and best practices
This guide collection is available under the MIT License. Feel free to use, modify, and distribute as needed for your projects and teams.
Built for modern React development π
For specific implementation details, dive into the individual guides. Each guide is designed to be comprehensive yet practical, with real-world examples and clear migration paths from legacy patterns.