Raja Muhammad Asher
Raja Muhammad Asher

Raja Muhammad Asher

Explain about types of side effects in React
component.

Photo by Lautaro Andreani on Unsplash

Explain about types of side effects in React component.

Raja Muhammad Asher's photo
Raja Muhammad Asher
·Aug 26, 2022·

1 min read

There are two common kinds of side effects in React components: those that don’t require cleanup, and those that do.

Effects Without Cleanup

Sometimes, we want to run some additional code after React has updated the DOM. Network requests, manual DOM mutations, and logging are common examples of effects that don’t require a cleanup.

Effects with Cleanup

We might want to set up a subscription to some external data source. In that case, it is important to clean up so that we don’t introduce a memory leak!

Sources:

Using the Effect Hook –. (n.d.). React. reactjs.org/docs/hooks-effect.html

 
Share this