Course contentsShow
← React
Lesson 2303 of 2,39650. Performance: Optimization TechniquesFree lesson

The isPending Flag for Loading States

Use the isPending boolean returned by useTransition to show inline loading indicators without blocking user input.

The isPending Flag for Loading States

What you'll learn: How to use the isPending boolean from useTransition to display inline loading indicators without freezing the UI.

When you call useTransition(), it returns an array with two values: [isPending, startTransition]. You've already learned that startTransition marks updates as non-urgent. Now we focus on the first value: isPending.

What isPending Tells You

The isPending flag is a boolean that becomes true when a transition is in progress and false when it completes. This gives you a precise signal: "React is working on that non-urgent update you requested, but it's not done yet."

Why This Matters

Without isPending, you'd mark an update as non-urgent and then... nothing. The user wouldn't know anything is happening. They might click again, thinking it didn't work. With isPending, you can show inline feedback—a spinner, dimmed content, a loading message—while keeping the interface fully interactive.

The Pattern

const [isPending, startTransition] = useTransition();

function handleSearch(query) {
  startTransition(() => {
    setSearchResults(filterData(query));
  });
}

return (
  <>
    <input onChange={e => handleSearch(e.target.value)} />
    {isPending && <span>Loading...</span>}
    <ResultsList data={searchResults} />
  </>
);

The input remains responsive because the expensive filter operation is non-urgent. Meanwhile, isPending is true, so you show "Loading...". When React finishes, isPending flips to false and the indicator disappears.

The Key Difference

Unlike traditional loading states that block everything, isPending lets you show feedback without sacrificing interactivity. The user can keep typing, clicking, scrolling—React just delays committing the heavy update until it's ready.

Key Takeaway: The isPending flag from useTransition provides a built-in loading state that's synchronized with non-urgent updates, letting you show feedback without blocking user input.