Optimistically Update Multiple Values in State Using React's setState

Erik Aybar
InstructorErik Aybar

Share this video with your friends

Send Tweet

We'll add a method to our class-based React component and immediately update state before firing off our request. Using a setState updater function, we will update component state based on previous state and toggle the "liked" status of a tweet upon the user clicking the heart icon. We will simultaneously increment or decrement the target tweet's likes property and appropriately add or remove the tweetId from the likedTweets array.

Ben Polinsky
Ben Polinsky
~ 2 years ago

"Catched" :)