I'm making a simple week calendar in React where I need to display columns with hours. A calendar will be generated onClick and based on the actual week number will show the whole week mon-sun. I'm using Moment.js to manage date.
What I'm trying to do is to increase the day number by 1 with every map loop. Right now I know how to display the right day number for the actual day. But how can I increase it by 1 with every loop? I tried this solution How increment id tag with map function in React . It works on id, but it didn't work with this example.
I display the day number using this code:
{moment(date).format(`DD/MM/YYYY`)}
I'd be glad for any tips or advice. Here is a little glimpse at my code:
const CalendarAdmin = ({openModal}) => {
const { active, setActive, sorted } = useContext(CalendarContext)
function addCalendar() {
setShow(true);
}
const [show, setShow] = useState(false);
const date = new Date();
const currentDate = moment(date).format('DD/MM/YYYY');
const currentWeek = moment(date).format('w');
const currentDay = moment(date).format('D');
const renderWeek = () => {
return (
<div className="calendar-content">
<h1>Calendar 1</h1>
<h1>Okres czasu: 14.11 - 20.11 ({currentWeek})</h1>
<div className="calendar-days">
{dayNames.map((item, dayIndex) =>
<div className="day-column" >
<h2 key={dayIndex}>{item.longName}</h2>
<h2>{item.testDate}</h2>
{moment(date).format(`DD/MM/YYYY`)}
{hours.map((hour, hourIndex) => {...