/performance-tools:react-concurrency-and-memoizationfrom performance-tools
React 18+ concurrency features and strategic memoization techniques. PROACTIVELY activate for: (1) Using useTransition for non-urgent updates, (2) useDeferredValue for deferred rendering, (3) Strategic useMemo and useCallback, (4) React.memo for expensive components, (5) Profiling re-renders. Triggers: "react performance", "useTransition", "useDeferredValue", "useMemo", "useCallback", "React.memo", "re-render", "bottleneck", "profiler"
Ships in performance-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill teaches the modern React performance paradigm, focusing on leveraging concurrent features to maintain UI responsiveness and applying memoization techniques strategically to prevent unnecessary computational work and re-renders.
React 18 introduced a fundamental shift from blocking, synchronous rendering to interruptible, concurrent rendering. This enables React to prepare multiple versions of the UI simultaneously and prioritize urgent updates over less important ones.
Urgent updates: User interactions that should feel immediate (typing, clicking, hovering) Transition updates: Non-urgent UI updates that can be deferred (search results, navigation)
React can now interrupt rendering of a transition to handle urgent updates, keeping the UI responsive.
The useTransition hook marks state updates as non-urgent transitions, allowing React to keep the UI responsive by de-prioritizing heavy rendering work.
import { useState, useTransition } from 'react'
function SearchPage() {
const [query, setQuery] = useState('')
const [results, setResults] = useState([])
const [isPending, startTransition] = useTransition()
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
const value = e.target.value
// Urgent: Update input immediately
setQuery(value)
// Non-urgent: Defer expensive search computation
startTransition(() => {
const searchResults = performExpensiveSearch(value)
setResults(searchResults)
})
}
return (
<div>
<input value={query} onChange={handleChange} />
{isPending && <Spinner />}
<SearchResults results={results} />
</div>
)
}
The input field stays responsive while search results are computed in the background.
function TabContainer() {
const [activeTab, setActiveTab] = useState('about')
const [isPending, startTransition] = useTransition()
function selectTab(tab: string) {
startTransition(() => {
setActiveTab(tab)
})
}
return (
<>
<TabButtons active={activeTab} onSelect={selectTab} />
{isPending && <Spinner />}
<TabContent tab={activeTab} />
</>
)
}
function FilteredList({ items }: { items: Item[] }) {
const [filter, setFilter] = useState('')
const [filteredItems, setFilteredItems] = useState(items)
const [isPending, startTransition] = useTransition()
function handleFilterChange(value: string) {
setFilter(value) // Urgent: Update input
startTransition(() => {
// Non-urgent: Filter large list
const filtered = items.filter(item =>
item.name.toLowerCase().includes(value.toLowerCase())
)
setFilteredItems(filtered)
})
}
return (
<>
<input
value={filter}
onChange={(e) => handleFilterChange(e.target.value)}
placeholder="Filter items..."
/>
<div className={isPending ? 'loading' : ''}>
{filteredItems.map(item => <ListItem key={item.id} item={item} />)}
</div>
</>
)
}
The useDeferredValue hook creates a deferred version of a value, allowing React to prioritize rendering other parts of the UI first.
import { useState, useDeferredValue, memo } from 'react'
function App() {
const [query, setQuery] = useState('')
const deferredQuery = useDeferredValue(query)
return (
<>
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
{/* This component re-renders with the deferred value */}
<SlowList query={deferredQuery} />
</>
)
}
// Must be memoized to benefit from deferredValue
const SlowList = memo(function SlowList({ query }: { query: string }) {
const items = useMemo(() => {
// Expensive computation
return filterItems(query)
}, [query])
return <List items={items} />
})
function Dashboard() {
const [value, setValue] = useState(0)
const deferredValue = useDeferredValue(value)
return (
<>
<input
type="range"
value={value}
onChange={(e) => setValue(Number(e.target.value))}
/>
{/* Slider stays responsive while chart updates in background */}
<ExpensiveChart value={deferredValue} />
</>
)
}
function SearchResults({ query }: { query: string }) {
const deferredQuery = useDeferredValue(query)
const isStale = query !== deferredQuery
return (
<div style={{ opacity: isStale ? 0.5 : 1 }}>
<Results query={deferredQuery} />
</div>
)
}
Memoization is an optimization technique that should be applied only after profiling has identified a clear performance bottleneck.
Use useMemo to cache expensive calculations between re-renders:
function TodoList({ todos, filter }: { todos: Todo[], filter: string }) {
// GOOD: Expensive filtering operation
const filteredTodos = useMemo(() => {
return todos.filter(todo => {
// Complex matching logic
return performExpensiveMatch(todo, filter)
})
}, [todos, filter])
return <List items={filteredTodos} />
}
// BAD: Cheap calculation, useMemo adds overhead
const sum = useMemo(() => a + b, [a, b])
// GOOD: Just calculate directly
const sum = a + b
// BAD: Creating objects/arrays for immediate use
const styles = useMemo(() => ({ color: 'red' }), [])
// GOOD: Create inline
const styles = { color: 'red' }
Use useCallback when a function is passed as a prop to a memoized component:
function TodoApp() {
const [todos, setTodos] = useState<Todo[]>([])
// GOOD: Prevents TodoList re-renders when function reference changes
const handleToggle = useCallback((id: string) => {
setTodos(todos => todos.map(todo =>
todo.id === id ? { ...todo, done: !todo.done } : todo
))
}, [])
return <MemoizedTodoList todos={todos} onToggle={handleToggle} />
}
const MemoizedTodoList = memo(TodoList)
// BAD: Function not passed to memoized component
const handleClick = useCallback(() => {
console.log('clicked')
}, [])
// GOOD: Just define inline
const handleClick = () => {
console.log('clicked')
}
Use React.memo to prevent re-renders when props haven't changed:
// GOOD: Expensive component with stable props
const ExpensiveComponent = memo(function ExpensiveComponent({
data,
onAction
}: {
data: Data,
onAction: () => void
}) {
// Complex rendering logic
return <ComplexVisualization data={data} onAction={onAction} />
})
// BAD: Simple component with cheap rendering
const SimpleComponent = memo(function SimpleComponent({ text }: { text: string }) {
return <p>{text}</p>
})
// The memo overhead exceeds the rendering cost
const Chart = memo(
function Chart({ data }: { data: ChartData[] }) {
return <ExpensiveChart data={data} />
},
(prevProps, nextProps) => {
// Custom comparison: only re-render if data length or first item changed
return (
prevProps.data.length === nextProps.data.length &&
prevProps.data[0]?.value === nextProps.data[0]?.value
)
}
)
Is the component/calculation expensive?
├─ NO → Don't memoize
└─ YES → Have you profiled?
├─ NO → Profile first with React DevTools
└─ YES → Did profiling show a problem?
├─ NO → Don't memoize
└─ YES → Apply appropriate memoization:
├─ Expensive calculation → useMemo
├─ Function passed to memo component → useCallback
└─ Expensive component → React.memo
Memoization relies on referential equality. Props must have the same reference to prevent re-renders.
// BAD: New object every render
function Parent() {
return <Child config={{ theme: 'dark' }} />
}
// GOOD: Memoized object
function Parent() {
const config = useMemo(() => ({ theme: 'dark' }), [])
return <Child config={config} />
}
// BETTER: If static, define outside component
const CONFIG = { theme: 'dark' }
function Parent() {
return <Child config={CONFIG} />
}
// BAD: New array every render
function Parent() {
return <Child items={[1, 2, 3]} />
}
// GOOD: Static array outside component
const ITEMS = [1, 2, 3]
function Parent() {
return <Child items={ITEMS} />
}
// BAD: Memoizing everything by default
const Component = memo(function Component({ value }: { value: number }) {
const doubled = useMemo(() => value * 2, [value])
const handleClick = useCallback(() => console.log(value), [value])
return <button onClick={handleClick}>{doubled}</button>
})
// All this memoization adds overhead with no benefit
// BAD: Synchronous expensive computation in event handler
function handleSearch(query: string) {
setQuery(query)
// This blocks the UI
const results = performVeryExpensiveSearch(query)
setResults(results)
}
// GOOD: Defer with useTransition
function handleSearch(query: string) {
setQuery(query)
startTransition(() => {
const results = performVeryExpensiveSearch(query)
setResults(results)
})
}
// BAD: Mutating array directly
const handleAdd = useCallback(() => {
todos.push(newTodo) // Breaks React's change detection
setTodos(todos)
}, [todos])
// GOOD: Creating new array
const handleAdd = useCallback(() => {
setTodos([...todos, newTodo])
}, [todos])
// BETTER: Using functional update
const handleAdd = useCallback(() => {
setTodos(todos => [...todos, newTodo])
}, [])
// BAD: Missing dependencies
const filtered = useMemo(() => {
return items.filter(item => item.category === category)
}, [items]) // Missing 'category' dependency!
// GOOD: Complete dependencies
const filtered = useMemo(() => {
return items.filter(item => item.category === category)
}, [items, category])
// BAD: Wrapping urgent input update
function handleChange(e) {
startTransition(() => {
setValue(e.target.value) // Input will feel sluggish
})
}
// GOOD: Only wrap non-urgent updates
function handleChange(e) {
setValue(e.target.value) // Urgent
startTransition(() => {
setSearchResults(expensiveSearch(e.target.value)) // Non-urgent
})
}
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub agentient/vibekit --plugin performance-tools6 skills in this plugin
/advanced-caching-strategiesMulti-layer caching strategies across CDN, browser, server, and database. PROACTIVELY activate for: (1) HTTP caching headers, (2) CDN configuration, (3) Server-side caching with Redis, (4) Cache invalidation strategies, (5) ETag implementation. Triggers: "caching", "cache strategy", "CDN", "browser cache", "server cache", "redis", "cache invalidation", "ETag", "Cache-Control"
/browser-runtime-performance-profilingBrowser runtime profiling with Chrome DevTools and Core Web Vitals optimization. PROACTIVELY activate for: (1) Using Chrome Performance panel, (2) Analyzing flame charts, (3) Diagnosing long tasks, (4) Core Web Vitals optimization, (5) Memory profiling. Triggers: "devtools", "performance panel", "lighthouse", "flame graph", "jank", "long task", "fps", "layout thrashing", "core web vitals"
/frontend-bundle-analysis-and-optimizationBundle analysis and optimization strategies for Next.js applications using Webpack and Turbopack. PROACTIVELY activate for: (1) Analyzing bundle size, (2) Implementing code splitting, (3) Configuring tree shaking, (4) Dynamic imports, (5) Webpack/Turbopack configuration. Triggers: "bundle size", "webpack", "turbopack", "code splitting", "tree shaking", "lazy loading", "bundle analyzer", "dynamic import"
/nextjs-rsc-performance-patternsPerformance optimization patterns for Next.js 14+ React Server Components. PROACTIVELY activate for: (1) Optimizing RSC data fetching, (2) Implementing streaming with Suspense, (3) Configuring caching and revalidation, (4) Parallel data fetching, (5) Partial Prerendering. Triggers: "rsc", "server component", "nextjs performance", "data fetching", "caching", "revalidate", "suspense", "streaming", "partial prerendering"
/python-advanced-profiling-and-optimizationAdvanced Python profiling with cProfile, py-spy, and optimization techniques including Python 3.13 features. PROACTIVELY activate for: (1) CPU profiling with cProfile, (2) Flame graph generation with py-spy, (3) Memory optimization, (4) Async performance patterns, (5) Python 3.13 JIT and free-threaded mode. Triggers: "python performance", "cProfile", "py-spy", "flame graph", "memory optimization", "async performance", "JIT", "GIL"
Other plugins' skills for the same job