I was trying making a clock using React (tsx), but for some reason when I tried printing hours and minutes inside a Component, It said it cannot find the name "hh". I tried also using 'var' instead of 'let' but it gives the same message.
Here's the code:
import styled from "styled-components";
const Clock = () => {
setInterval(() => {
let date = new Date();
let hh: string | number = date.getHours();
let mm = date.getMinutes();
let day = date.getDate();
let dayweek = date.getDay();
let month = date.getMonth();
let year = date.getFullYear();
let ampm;
if (hh >= 12) {
hh = hh - 12;
ampm = "PM";
} else {
ampm = "AM";
}
if (hh == 0) {
hh = 12;
}
if (hh < 10) {
hh = `0${hh}`;
}
}, 1000);
return (
<ClockContainer>
<ClockTime>{hh}</ClockTime>
</ClockContainer>
);
};
const ClockContainer = styled.div`
flex: 0.3;
display: flex;
align-items: center;
font-family: Poppins;
`;
const ClockTime = styled.div`
font-size: 98px;
cursor: default;
user-select: none;
text-shadow: 3px 3px 8px #00000033;
color: var(--fontColor);
transition: all 500ms ease-in-out;
`;
export default Clock;