Skip to main content

Command Palette

Search for a command to run...

useEffect !== componentDidMount

Published
1 min read
T

I'm a Front End Developer in Korea.

I work for a company called Lunit, that develops AI software to diagnose cancer.

From the UK, I came to Korea as an English teacher, and managed to retrain myself, and break out into the programming industry 😎

One of useEffect's uses is to perform an effect when a component is first mounted, and not to repeat it. However, React's compiler always breathes down your neck about adding dependencies to useEffect's dependency array. Most of the time, sure, the dependencies don't change, so it makes no difference. Sometimes it does.

Today I solved this issue by offloading some of the work that I wanted the useEffect to do into a custom hook. More as a reminder to myself, I want to note - it's a definite solution you can use.