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.

Correct ways of dependency management

Correct ways of dependency management

Hello and welcome back, let's discuss the correct ways to handle dependencies and how to manage them correctly. Our goal should be that we only refetch whenever there is a need to actually fetch the data from the API. We have learned about the useEffect hook in the previous modules in great detail, but This specific lesson is dedicated to be with the APIs and what are the items that we should be considering specifically when using useEffectHook to call the APIs. So we should be utilizing the dependency array and we should figure out in the business logic what are the values or fields that can affect the data. Something like a user ID, a profile name or some flag that we have set on the UI. You should also be avoiding adding state that changes after every fetch. Something like the post that we have created or we have updated. So obviously when something is going to be updated to that post, if we put on the complete object of the post inside the dependency array, then it is definitely…

Contents