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

startTransition Without the Hook: Event Handler Use Cases

Use the standalone startTransition function to defer updates in event handlers without adding state to your component.

startTransition Without the Hook: Event Handler Use Cases

You'll learn: When and how to use the standalone startTransition function to defer updates in event handlers without adding React state to your component.

The Core Idea

You've used useTransition to mark state updates as non-urgent, but that hook returns isPending and requires you to add it to your component. When you're triggering updates in an event handler and don't need the pending flag, you can use the standalone startTransition function instead.

This is particularly useful when:

  • You're calling a state setter from a parent or imported module
  • You don't control the component's state directly
  • You simply want to deprioritize an update without adding extra state management

The Pattern

import { startTransition } from 'react';

function handleClick() {
  // Urgent: update immediately
  setInputValue(value);
  
  // Non-urgent: defer this expensive update
  startTransition(() => {
    setSearchResults(expensiveFilter(data, value));
  });
}

Think of startTransition as a wrapper you can apply anywhere, while useTransition is for components that need to show loading feedback.

When to Choose startTransition

Use the standalone function when:

  • You're in an event handler, not render logic
  • You don't need isPending to show UI feedback
  • You're calling setters from props or imported stores

Use the hook when:

  • You need isPending for loading spinners/skeletons
  • The component owns the state being updated

Key Takeaway: The standalone startTransition function gives you the performance benefits of deferring updates without requiring the useTransition hook—perfect for event handlers where you don't need pending state.