Passing Array Dependencies

In this lesson, we'll discuss how the useEffect function can be used for specific functionality, especially for passing arrays.

It’s interesting that the effect function is invoked every time there’s an update. That’s great, but it’s not always the desired functionality.

Using Effect for Specific Functionality

What if you want to run the effect function only when the component mounts?

That’s a common use case and useEffect takes a second parameter, an array of dependencies to handle this.

If you pass in an empty array, the effect function is run only on the mount — subsequent re-renders don’t trigger the effect function.

Get hands-on with 1000+ tech skills courses.