1 min read

useOptimistic and how it works internally

React's useOptimistic hook enables optimistic UI updates for async actions, though its internal complexity and connection to concurrent mode raises questions about error handling and state reversion.

frontend links/readings

Original Article

Author: React Team & JSer Published: 3/20/2024

Link: Read original article →

tl;dr

React's useOptimistic hook manages state dependent on async actions, enabling optimistic rendering before action completion. The hook's complexity stems from its integration with concurrent mode, raising questions about error detection and state reversion mechanisms.

My Thoughts

Not sure I 100% understand how it works underneath, it seems like a way of managing a state that depends on async actions, that does the optimistic rendering of a new state. But I have a lot of open questions about how it detect errors, how does it revert… They recommend to wait to use this until some library uses it. All the things that had to do with the concurrent mode are potentially dangerous.

This is my personal commentary on the original article. Please read the original article for the full context.