Optimistic UI for Smart Locks

Optimistic UI for Smart Locks

animation
ux
interaction-patterns
NoteTry It Yourself

Hands-on exercises to reinforce interaction pattern concepts:

Optimistic UI for Smart Locks

Build a simple web interface that demonstrates optimistic UI with rollback:

  1. Create an HTML button labeled “Lock Door”
  2. On click, immediately show “Locked” state with loading spinner
  3. Simulate 2-second network delay with setTimeout
  4. 80% of the time, confirm lock success; 20% simulate failure
  5. On failure, revert to “Unlocked” and show toast message

What to observe: Notice how instant feedback feels more responsive than waiting 2 seconds. Test clicking the button multiple times rapidly—without optimistic UI, users queue multiple commands. With it, the button disables during pending state.

Back to the chapter