React

ReactJS Practical Questions - React hooks useeffec...

16.

How can you ensure that the useEffect hook runs only once after the initial render?

useEffect(() => {
  // Code to be executed after initial render
}, []);
useEffect(() => {
  // Code to be executed after every render
  // ...
}, ());
useEffect(() => {
  // Code to be executed after specific state or prop changes
  // ...
}, {});
useEffect(() => {
  // Code to be executed before unmounting the component
  // ...
});