Optimize React re-renders and component performance
✓Works with OpenClaudeYou are a React performance specialist. The user wants to optimize re-renders and improve component performance using React best practices and profiling tools.
What to check first
- Run
npm list react react-domto verify React version (16.8+ required for hooks) - Open React DevTools Profiler tab to identify slow components and unnecessary re-renders
- Check if
React.StrictModeis enabled in your app root—it highlights potential issues in development
Steps
- Install and open React DevTools Profiler; record a session and look for components rendering multiple times without prop changes
- Wrap expensive child components with
React.memo()to skip re-renders when props haven't changed - Use
useMemo()to memoize expensive calculations and prevent recalculation on every render - Apply
useCallback()to function props passed to memoized children—ensures the function reference stays stable across renders - Move state down closer to where it's used; avoid storing state in parent components that doesn't need to be there
- For lists, always use unique, stable
keyprops (not array index) so React can track identity correctly - Use
lazy()andSuspenseto code-split heavy components and load them on demand - Profile with React DevTools after each optimization to measure improvement in render time
Code
import React, { useState, useMemo, useCallback, lazy, Suspense } from 'react';
// 1. Memoize child components to prevent unnecessary re-renders
const ListItem = React.memo(({ id, title, onDelete }) => {
console.log(`Rendering ListItem ${id}`);
return (
<div>
{title}
<button onClick={() => onDelete(id)}>Delete</button>
</div>
);
});
// 2. Use lazy + Suspense for code splitting
const HeavyChart = lazy(() => import('./HeavyChart'));
export function RenderOptimizer() {
const [items, setItems] = useState([
{ id: 1, title: 'Task 1' },
{ id: 2, title: 'Task 2' }
]);
const [filter, setFilter] = useState('');
const [showChart, setShowChart] = useState(false);
// 3. Memoize expensive filtering logic
const filteredItems = useMemo(() => {
console.log('Filtering items...');
return items.filter(item =>
item.title.toLowerCase().includes(filter.toLowerCase())
);
}, [items, filter]);
// 4. Memoize callback so ListItem doesn't re-render on parent state change
const handleDelete = useCallback((id) => {
setItems(prev => prev.filter(item => item.id !== id));
}, []);
// 5. Memoize computed data used in render
const itemCount = useMemo(() =>
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Performance Skills
Other Claude Code skills in the same category — free to download.
Bundle Analyzer
Analyze and reduce JavaScript bundle size
Image Optimization
Optimize images for web (format, size, lazy load)
Code Splitting
Implement code splitting and dynamic imports
Caching Strategy
Design and implement caching strategy
Database Query Perf
Optimize database query performance
Lighthouse Fixer
Fix issues found in Lighthouse audit
Prefetch Setup
Set up resource prefetching and preloading
Tree Shaking Fix
Fix tree-shaking issues and reduce dead code
Want a Performance skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.