import {useState} from "react";
import MyHeader from "./../components/MyHeader";
import MyButton from "./../components/MyButton";
const Home = () => {
const [curDate, setCurDate] = useState(new Date());
console.log(curDate);
const headText = `${curDate.getFullYear()}년 ${curDate.getMonth() + 1}월`;
const increaseMonth = () => {
setCurDate(
new Date(curDate.getFullYear(), curDate.getMonth() + 1, curDate.getDate())
);
};
return (
<div>
<MyHeader
headText={headText}
leftChild={<MyButton text={"<"} onClick={() => {}} />}
rightChild={<MyButton text={">"} onClick={increaseMonth} />}
/>
</div>
);
};
export default Home;
버튼 - 한달씩 증가하는 코드
const increaseMonth = () => {
setCurDate(
new Date(curDate.getFullYear(), curDate.getMonth() + 1, curDate.getDate())
);
};