Showing Stale Content During Transitions
What you'll learn: How to keep the old UI visible with visual feedback while new content renders in the background during a transition.
The Problem: Disappearing Content
When you use useTransition to mark a state update as non-urgent, React lets the current UI stay interactive while preparing the next screen. But here's the UX question: should you show a spinner and hide everything, or keep the old content visible?
Keeping Users Oriented
The beauty of transitions is that you can show the previous content with reduced opacity or other visual indicators while the new content renders. This prevents the jarring "flash of loading spinner" that makes users feel lost.
Think of it like viewing a photo gallery: when you click "next," you'd rather see the current photo fade slightly while the next one loads than stare at a blank screen.
The Pattern
function SearchResults({ query }) {
const [isPending, startTransition] = useTransition();
const [searchQuery, setSearchQuery] = useState('');
function handleSearch(newQuery) {
startTransition(() => {
setSearchQuery(newQuery);
});
}
return (
<div>
<input onChange={(e) => handleSearch(e.target.value)} />
<div style={{ opacity: isPending ? 0.5 : 1 }}>
<ExpensiveList query={searchQuery} />
</div>
</div>
);
}
The isPending flag tells you when a transition is in progress. You use it to dim the old results (opacity: 0.5) instead of hiding them. Users still see their previous search results—they just know something's updating.
Other Visual Indicators
Beyond opacity, you can add a loading bar, a subtle spinner overlay, or disable interactions—anything that signals "working on it" without yanking away content.
Key Takeaway: Use isPending to apply visual feedback (dimming, overlays, loading bars) to stale content during transitions, keeping users oriented instead of showing blank loading states.