DEV Community

Cover image for Developers might be using useEffect wrong this whole time

Developers might be using useEffect wrong this whole time

Sanchit Bajaj on March 22, 2023

Hi there everyone 👋, if you're a React Developer then there might be the case that you're misusing the useEffect hook in one way or another. I also...
Collapse
 
brense profile image
Rense Bakker

The way I usually look at useEffect is that its a hook to do anything that is not part of the react component lifecycle (mounting, rendering, updating, unmounting). That includes API requests, Executing initialization/config code for external libraries that are not written in React, adding window or document event listeners or listening/subscribing to websockets or other async events (always with cleanup function).