...

/

Using Dependencies Array with useEffect Hook

Using Dependencies Array with useEffect Hook

Learn why you need a 'dependencies array' with the “useEffect” hook and what difference it makes for the “useEffect” behavior.

Examine an example without dependencies array

Generally, the dependencies array with useEffect to improve rendering performance.

Look at the following exercise to help you understand how code is working without the dependencies array.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <meta name="theme-color" content="#000000" />
    <title>React App</title>
  </head>

  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root"></div>
  </body>
</html>

Explanation

When you run the above ...