Run useEffect Function with Change in State or Props

In this lesson, you will discover how the “useEffect” hook runs an inline function when a prop or state mentioned in the dependencies array changes.

Running effects after change in props or state

Dependencies array can be used to manage when side effects are run.

Below is a slightly advanced example of useEffect hook. Assume the application allows users to set a nickname using an input field. After the nickname is set, it fetches a personalized greeting message from an external API. The following exercise demonstrates this application.

Run the application. You should see something like this:

Get hands-on with 1400+ tech skills courses.