1

I am using CalendarList component of react-native-calendars within CalendarList I set pastScrollRange and futureScrollRange as per the conditions shown bellow

    const [showNextMonth, setShowNextMonth] = useState<number>(1)
    const [showPrevMonth, setShowPrevMonth] = useState<number>(1)

    useEffect(() => {
        setShowPrevMonth(moment(today).month() + 1 > moment(startDateToBeShown).month() + 1 ? 1 : 0)
        setShowNextMonth(moment(today).month() + 1 < moment(endDateToBeShown).month() + 1 ? 1 : 0)
    }, [startDateToBeShown, endDateToBeShown])

And using CalendarList as bellow

    <CalendarList
        ref={calendarRef}
        current={today}
        calendarHeight="auto"
        theme={calTheme}
        firstDay={1}
        dayComponent={generateDayComponent}
        monthFormat={'MMMM'}
        hideExtraDays={true}
        markedDates={formattedMergedDays}
        futureScrollRange={showNextMonth}
        pastScrollRange={showPrevMonth}
        maxDate={endDateToBeShown}
        scrollEnabled={true}
    />

The error I am getting only for pastScrollRange screenshot is attached below. The calculated value for pastScrollRange as per the current conditions and date will be 1. With this current implementation, I am getting errors. But if I manually set pastScrollRange value to 1 in the above effect then I won't get an error.

   setShowPrevMonth(1)

enter image description here

in usestate if I use default value 0 for both then also I am getting errors. If console in the library file initial value 0 is going for both of them. Please help me to resolve the issue.

Mahantesh
  • 347
  • 5
  • 20

0 Answers0