Restore Target Items in React State for Improved Optimistic UI Updates

Share this video with your friends

Send Tweet

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.

Steve
Steve
~ 7 years ago

This was a great course. Excellently instructed with great edge case coverage. I'm going to enjoy making use of this. Thanks very much

Erik Aybar
Erik Aybar(instructor)
~ 7 years ago

Thank you Steve! That means a lot to me 😃. I hope you came away having learned something new and gained some value from the course.

Jiwon
Jiwon
~ 7 years ago

thank you for your course. good job!

Christian
Christian
~ 6 years ago

Thanks for the course. Only one comment from me, maybe: we wouldn't normally do the data sorting in the event handler, but I understand this is probably for the sake of simplicity.

Devin Halladay
Devin Halladay
~ 3 years ago

Thank you for this! What would you do in the case that you are updating some state where the list IDs are not a linear sequence, such as a UUID?