Skip to content

[Suggestion]: Can you add a paragraph saying useOptimistic updater function should be called in transition? #7737

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

Open
gmoniava opened this issue Apr 14, 2025 · 0 comments

Comments

@gmoniava
Copy link

gmoniava commented Apr 14, 2025

Summary

Here:

const [optimisticState, addOptimistic] = useOptimistic(state, updateFn);

When you call updateFn without transition react gives warning:

Warning: An optimistic state update occurred outside a transition or action. To fix, move the update to an action, or wrap with startTransition.

Page

https://react.dev/reference/react/useOptimistic

Details

Can you also add this information (which is in the warning) in the docs so that it is not only as a warning in the console?
The example in the docs may further confuse people because formAction is not wrapped in transition (but apparently react does that for you when it is passed as action prop - and many might not realize this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant