[英]React Calendar Timeline doesn't show fetched data
所以我來解決這個問題。 奇怪的是,即使我知道它在數組中,React-Calendar-Timeline 組件也不顯示獲取的項目。 但是,當我打開檢查元素時,項目會按應有的方式呈現,並且一切都開始工作了。
我嘗試通過在獲取數據時實現加載屏幕來解決問題,但是問題仍然存在。
以下是時間線組件代碼:
{!isLoading ? (
<CalendarContainer>
<Timeline
groups={rooms}
items={tenantsInCalendar} // this part is not rendering at the first time
defaultTimeStart={startDate}
defaultTimeEnd={endDate}
canResize={"both"}
stackItems
onItemSelect={handleItemClick}
onItemDeselect={() => dispatch(setCurrentTenant(null))}
minZoom={24 * 60 * 60 * 1000} // min zoom is 24 hours.
dragSnap={24 * 60 * 60 * 1000} // snap is at 24 hours.
canMove={true}
itemHeightRatio={0.75}
onItemMove={handleItemMove}
onItemResize={handleItemResize}
timeSteps={{
day: 1,
month: 1,
year: 1,
}}
></Timeline>
</CalendarContainer>
) : (
<Spinner />
)}
獲取方法:
useEffect(() => { // converting fetched data to object for better/faster properties changement
fetchedTenants &&
setTenantsToObject(convertTenantsToObject(fetchedTenants));
}, [fetchedTenants]);
useEffect(() => { // converting tenants to other object type for calendar to understand. This data is rendered in calendar component.
tenantsToObject &&
setTenantsInCalendar(
convertTenantsToCalendarObjectItems(Object.values(tenantsToObject))
);
}, [tenantsToObject]);
useEffect(() => {
if (tenantsInCalendar.length > 0 && isLoading) {
handleTimeout(1000);
}
}, [tenantsInCalendar]);
const handleTimeout = (time) => { // sets some timeout for calendar to really render data at the first time. However, still doesn't work as it should.
setTimeout(() => {
setIsLoading(false);
}, time);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.