react-concurrency-and-memoization
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"
What this skill does
# React Concurrency and Memoization
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.
## Concurrent Rendering Model
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.
### Key Concepts
**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.
## Strategic Concurrency with useTransition
The `useTransition` hook marks state updates as non-urgent transitions, allowing React to keep the UI responsive by de-prioritizing heavy rendering work.
### Basic Pattern
```tsx
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.
### Tab Switching Pattern
```tsx
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} />
</>
)
}
```
### Conditional Rendering Optimization
```tsx
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>
</>
)
}
```
## Deferring Values with useDeferredValue
The `useDeferredValue` hook creates a deferred version of a value, allowing React to prioritize rendering other parts of the UI first.
### Basic Pattern
```tsx
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} />
})
```
### Live Chart Pattern
```tsx
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} />
</>
)
}
```
### Stale Content Indicator
```tsx
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>
)
}
```
## Purposeful Memoization
Memoization is an optimization technique that should be applied **only after profiling** has identified a clear performance bottleneck.
### When to Use useMemo
Use `useMemo` to cache expensive calculations between re-renders:
```tsx
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} />
}
```
### When NOT to Use useMemo
```tsx
// 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' }
```
### When to Use useCallback
Use `useCallback` when a function is passed as a prop to a memoized component:
```tsx
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)
```
### When NOT to Use useCallback
```tsx
// BAD: Function not passed to memoized component
const handleClick = useCallback(() => {
console.log('clicked')
}, [])
// GOOD: Just define inline
const handleClick = () => {
console.log('clicked')
}
```
### When to Use React.memo
Use `React.memo` to prevent re-renders when props haven't changed:
```tsx
// 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
```
### Custom Comparison Function
```tsx
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
)
}
)
```
## Memoization Decision Guide
```
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 → useCallbackRelated in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.