您好,我正在尝试获取每个开始日期和结束日期之间的所有日期,然后将这些日期放入我的 react-native-calendar 组件中。一切正常,但实际上我需要 CTRL + S 三次我的项目才能在我的日历中包含值,你知道如何直接拥有它吗?
这是我的代码:
const myConstrucion = async () => {
let user_id = await AsyncStorage.getItem('user_id');
const _id = user_id;
try {
let res = await axios.get(`https://myseenapp.herokuapp.com/constructionSite/${_id}`);
let data = res.data;
setConstruction(data);
let st = data
.map(e => e.startDate.split("-").reverse().join("-"))
.forEach((day) => { setStartDate(day)})
let et = data
.map(e => e.endDate.split("-").reverse().join("-"))
.forEach((day) => { setEndDate(day)})
let now = moment(startD);
let end = moment(endD);
while (now <= end){
dateArray.push(now.format("YYYY-MM-DD"));
now.add(1, 'days');
dateArray.forEach((day) => {
newDaysObject[day] = {
textColor: "white",
color: 'gold',
selected: true,
}
return dateArray;
})
}
}
catch (err) {
console.log(err)
}
};
我也有我的 useEffect :
useEffect(() => {
myConstrucion()
}, [])