I'm trying to render components with a loop. What I did was to use array.map inside a JSX return block of the function component. The component is to render each individual dates contained in the list called 'mountDates'. But it is not rendering the items. Here is my code:
import React, {useEffect} from 'react';
import {View, Text, StyleSheet} from 'react-native';
import {globalStyles} from '../../styles/global';
import AgendaItem from './agendaItem';
export default function Agenda({onDayChange, startDate, endDate}) {
const mountDates = [];
useEffect(() => {
const getDates = (startDate, endDate) => {
let currentDate = startDate;
console.log(startDate, endDate);
while (currentDate.getTime() <= endDate.getTime()) {
mountDates.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
};
getDates(startDate, endDate);
}, []);
return (
<View style={styles.container}>
{mountDates.map((date, i) => {
return <AgendaItem key={i.toString()} date={date} />;
})}
</View>
);
}
mountDatesas a prop.