Introduced in React 18, useDeferredValue allows developers to defer updating a non-critical portion of the UI, keeping urgent inputs responsive during heavy background rendering operations.
useDeferredValue is similar to debouncing or throttling, but unlike setTimeout implementations, it integrates directly with React's Concurrent Rendering pipeline and fires immediately after main screen updates finish.
flowchart TD
Input["User Types Keystroke"] --> HighPriority["High Priority: Update Input Field Instantly"]
HighPriority --> LowPriority["Deferred Priority: Render Heavy Filtered List"]
import React, { useState, useDeferredValue, memo } from 'react';
// Memoized Heavy List Component
const HeavyList = memo(function HeavyList({ query }) {
console.log('HeavyList rendering for query:', query);
// Synthesize large computationally expensive list rendering
const items = Array.from({ length: 10000 }, (_, i) => `${query} Item #${i + 1}`);
return (
<ul>
{items.slice(0, 100).map((item, idx) => (
<li key={idx}>{item}</li>
))}
</ul>
);
});
export default function DeferredSearchDemo() {
const [query, setQuery] = useState('');
// Defer heavy list recalculation
const deferredQuery = useDeferredValue(query);
const isStale = query !== deferredQuery;
return (
<div className="search-card">
<h2>Concurrent Deferred Value Search</h2>
{/* Keystrokes inside input update instantly with ZERO lag */}
<input
type="text"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Type fast to see deferred responsiveness..."
/>
<div style={{ opacity: isStale ? 0.5 : 1, transition: 'opacity 0.2s' }}>
<HeavyList query={deferredQuery} />
</div>
</div>
);
}
React.memo: useDeferredValue works best when the child component receiving the deferred value is wrapped in React.memo.useDeferredValue defers React UI rendering. For throttling backend HTTP requests, continue using standard network request debouncing.What is the visual indication of a stale deferred render in the code example above, and how is it styled?
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
You've completed this section! Take a quick 5-question quiz to check your understanding.