How I use React’s useEffect

As if reasoning with component lifecycles in React class components wasn’t hard enough, things got even trickier with the advent of React functional components and the useEffect hook. Here’s how I ended up using them.

Image for post
Image for post
Photo by Ferenc Almasi on Unsplash
  1. Start with an empty dependency array. This means that your effect will only run once. Often times, this is what you want.

Of course, it’s React’s philosophy that there isn’t one way of doing things, nor is there “one blessed way” in the documentation. So, this is why the title of this post is “How I use React’s useEffect”. Buyer beware :)

Co-founder & CTO @ AgentRisk. Former infra-tech guy (storage, networks). Startup nerd. Always building cool side-projects. #LongLA

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store