useEffect

Pascual Vila
Frontend Instructor.
useEffect is a hook that allows you to perform side effects in functional components. This hook is used to handle tasks such as subscribing to events, making HTTP requests, manipulating the DOM, among others.
Example of useEffect:
{`import React, { useState, useEffect } from "react";
function Clock() {
const [time, setTime] = useState(new Date().toLocaleTimeString());
useEffect(() => {
const intervalId = setInterval(() => {
setTime(new Date().toLocaleTimeString());
}, 1000);
return () => clearInterval(intervalId);
}, []);
return <h1>{time}</h1>;
}
export default Clock;`}