Optimistic UI merges temporary state into the screen immediately after an action. Success confirms it; failure removes it or shows an error.
The demo increments a reaction immediately, then follows either confirmation or rollback. Design the feedback carefully for hard-to-reverse operations such as payment or inventory.
When to use
Use it for likely-to-succeed, reversible actions such as reactions, checks, and comments.