export const myFunction = () => {
const [myText, setMyText] = useState("");
const [localTime, setLocalTime] = useState(new Date().getHours());
useEffect(() => {
function timeInterval() {
const currentHour = new Date().getHours();
if (localTime !== currentHour) {setLocalTime(currentHour);}
if (localTime >= 1 && localTime < 12) {setMyText("Morning");}
else if (localTime >= 12 && localTime < 17) {setMyText("Afternoon");}
}
timeInterval();
const myInterval = setInterval(timeInterval, 1000);
return () => clearInterval(myInterval);
}, [myText, localTime]);
return (
<h1>
{myText}
</h1>
);
}