From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Handling race conditions

Handling race conditions

Hello and welcome back. In this video, we are going to discuss how we can handle and avoid raise conditions when using useEffect. Hello and welcome back. In this video, we are going to discuss how we can handle the raise conditions when using the useEffect hook. Let's address the problem first. When we trigger multiple requests very quickly, something like a button that is sending an API call and we just click it frequently so many times within one second or we are having a user switches, a filter or a search button, then the old request is in the queue and it wouldn't have been returned back. In the meanwhile, we have shooted down the other request. So consider we are making an API call for fetching the users and we just click the button for searching the user about 3 to 5 times within a second. So the first request will be in the queue processing and in the meanwhile we have sent down the other request too. Since HTTP is a stateless protocol, so it is going to treat every request…

Contents