Skip to content

fix action pattern in useTransition / useOptimistic #7796

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

Merged
merged 2 commits into from
Apr 30, 2025

Conversation

rickhanlonii
Copy link
Member

When you create a function with the action suffix, it's because you know that it's being called inside of a transition. So it doesn't really make sense to immediately wrap the body of a function named sendMessageAction with startTransition.

The reason the useOptimistic example did this is because the child Thread component was not awaiting the action prop that was passed in, but the pattern should really be that you await the action prop if you expose it. That allows the action callback to be either synchronous or asynchronous without requiring an additional startTransition to wrap the await in the action.

@rickhanlonii rickhanlonii merged commit a3e9466 into reactjs:main Apr 30, 2025
8 checks passed
@rickhanlonii rickhanlonii deleted the rh/fix-uo-docs-2 branch April 30, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants