Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rajaahsan365 opened this issue Dec 18, 2024 · 0 comments
Labels

Comments

@rajaahsan365
Copy link

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant