Explain the useEffect() Hook The useEffect Hook allows you to perform side effects in your components like data fetching, direct DOM updates, timers like setTimeout(), and much more. This hook accepts two arguments: the callback and the dependencies, which allow you to control when the side effect is executed. Note: The second argument is optional

PHOTO EMBED

Thu Sep 01 2022 13:06:49 GMT+0000 (Coordinated Universal Time)

Saved by @EMR4HKLMN #javascript

import React, {useState, useEffect} from 'react';

const App = () => {
  const [loading, setLoading] = useState(false);
  
  useEffect(() => {
    setLoading(true);
    setTimeout(() => {
      setLoading(false);
    }, 2000);
  }, []);
  
  return(
    <div>
      // ...
    </div>
  )
}

export default App;
content_copyCOPY

https://www.freecodecamp.org/news/react-interview-questions-and-answers/