facebook/react

[React 19] Proposal: Enhancing useTransition Hook with Timed Start Transition Feature

rajaahsan365 opened this issue · 0 comments

Summary

We propose enhancing React's startTransition function to accept an optional second parameter: a timeout duration (durationInMs). This will ensure the transition runs for at least the specified time, even if the internal logic resolves earlier, enabling smoother UI updates and animations.

#Proposed API
startTransition(callback, durationInMs);

  • callback: Executes state updates or operations as a transition.
  • durationInMs (Optional): Ensures the transition takes a minimum time, adding a delay if the callback resolves sooner.

startTransition(() => { setData(fetchData()); }, 500); // Ensures a minimum 500ms transition
If fetchData resolves in 200ms, the UI remains in a "pending" state for 500ms, ensuring a smoother experience.

#Benefits

  • Enhanced UX: Prevents abrupt UI updates by synchronizing transitions with animations or loaders.
  • Simplified Code: Reduces reliance on setTimeout hacks for timing.
  • Backward Compatible: Fully optional, retaining existing functionality.
  • This addition aligns with React's goal of delivering seamless developer and user experiences. We invite the community to discuss and refine this idea.