Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Restore Target Items in React State for Improved Optimistic UI Updates


    Our initial, simplified approach may be fine for many scenarios, but is not the most robust solution. By simply taking a snapshot of current state (our list of items) and restoring it after a failure, we’ve left the potential for inconsistent state due to the fact that between taking the snapshot and failure, the user could have performed additional actions.

    One solution is to, instead of taking a snapshot of our entire list of items, take a snapshot of the target item and use that upon failure to more precisely restore the individual item to state. This eliminates the possibility of incorrectly restoring items to state which have been successfully deleted.