import { useState, useEffect } from "react"; import moment from "moment"; import styles from "./calender.module.scss"; const Calender = ({ selectDate, setSelectDate }) => { const [dateList, setDateList] = useState([]) const [week, setWeek] = useState(["일", "월", "화", "수", "목", "금", "토"]) useEffect(() => { getDate(selectDate) }, []) function getDate(oneDay) { let dateArr = [] let lastWeek = moment(oneDay).subtract(7, 'days') const nextWeek = moment(oneDay).add(7, 'days') while (lastWeek.isBefore(nextWeek)) { dateArr.push({ date: lastWeek.format('YYYY-MM-DD'), day: lastWeek.format('d') }) lastWeek.add(1, 'days') } const resultArr = dateArr.map(el =>
setSelectDate(el.date)}> {moment(el.date).isSame(oneDay) || el.date.split('-')[2] === "01" ? {moment(el.date).format('YYYY.MM')} : ""}
{moment(el.date).format('DD')} {moment(el.date).isSame(oneDay) ? "오늘" : week[el.day]}
) setDateList(resultArr) } return ( <> {console.log("date==", selectDate)}
{dateList.map(el => el)}
) } export default Calender