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:
This repository also includes a published ESLint configuration package for React projects:
@10xscale/eslint-modern - A shareable ESLint configuration for React projects, designed to enforce consistent code style and best practices across your codebase. Built for use with ESLint v9+ Flat Config.
See the package README for installation and usage instructions.
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 |
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 |
# 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
Install the published ESLint configuration package:
# Install the complete ESLint config package
npm install --save-dev @10xscale/eslint-modern
# Or install with all peer dependencies at once
npm install --save-dev @10xscale/eslint-modern @babel/eslint-parser @eslint/eslintrc @eslint/js eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-sonarjs eslint-plugin-unicorn eslint-import-resolver-alias eslint-plugin-jsdoc
See the package README for detailed installation and usage instructions.
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
// 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: 'john@example.com'
};
it('renders user information correctly', () => {
render(<UserCard user={mockUser} />);
expect(screen.getByText('John Doe')).toBeInTheDocument();
expect(screen.getByText('john@example.com')).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-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"]
}
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.
Install the package:
# Using npm
npm install --save-dev @10xscale/eslint-modern
npm install --save-dev eslint-import-resolver-alias
# Using yarn
yarn add --dev @10xscale/eslint-modern
# Using pnpm
pnpm add -D @10xscale/eslint-modern
Install the package and all required peer dependencies:
# Using npm
npm install --save-dev @10xscale/eslint-modern @babel/eslint-parser @eslint/eslintrc @eslint/js eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-sonarjs eslint-plugin-unicorn eslint-import-resolver-alias eslint-plugin-jsdoc
# Using yarn
yarn add --dev @10xscale/eslint-modern @babel/eslint-parser @eslint/eslintrc @eslint/js eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-sonarjs eslint-plugin-unicorn eslint-import-resolver-alias eslint-plugin-jsdoc
# Using pnpm
pnpm add -D @10xscale/eslint-modern @babel/eslint-parser @eslint/eslintrc @eslint/js eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-sonarjs eslint-plugin-unicorn eslint-import-resolver-alias eslint-plugin-jsdoc
Note: You must also install all listed peer dependencies. Check the
peerDependencies
section inpackage.json
for the required versions.
Important: This config is published as an ES module. You must set βtypeβ: βmoduleβ in your projectβs
package.json
to use it, or use the.mjs
extension for your ESLint config file.
Add this to your package.json
:
{
"type": "module"
}
eslint.config.js
(or .mjs
) file in your project root:// eslint.config.js
import config from '@10xscale/eslint-modern';
export default [
...config,
// Add your custom rules or overrides here
];
If you cannot use type: "module"
, rename your config to eslint.config.mjs
and use the same import/export syntax.
When updating this package, always ensure your projectβs peer dependencies match the versions specified in package.json
. Update them as needed to avoid version conflicts.
Contributions, issues, and suggestions are welcome! Please open an issue or pull request on the repository.
For questions or support, contact the maintainers via the repositoryβs issue tracker.