What are the disadvantages of refactoring multiple UseEffect into one?



I have used multiple useEffect for different callback functions. Now, I get to know that I can refactor multiple useEffect into a single one, all the callback functions have different dependencies so is it a great idea to refactor all useEffect into a single one or is there any better approach to optimise the code and no need to use of multiple useEffect or use of multiple useEffect is common practice?


Its depends on your dependencies (of your useEffect) and component , i think its better to split useEffect for each your concept , for example in one useEffect you have api call and in the other useEffect you have event listener and remove listeners and dependencies , because i think if you combine them , it may create unexpected re-render and side effect

Answered By – tmohammad78

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More