BugiDev / react-native-calendar-strip

Easy to use and visually stunning calendar component for React Native.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read property 'scrollToDate'

strelov1 opened this issue · comments

When I try to select another date with the ref I have this error

TypeError: Cannot read property 'scrollToDate'

CleanShot 2023-05-04 at 10 48 21@2x

Here is my configuration

const calendarRef = useRef(null);
const nextDay = () => {
       if (calendarRef.current) {
            const addOneDay = new Date(currentDate);
            addOneDay.setDate(currentDate.getDate() + 1);
            calendarRef.current.setSelectedDate(addOneDay.toISOString())
        }
}

return (
<CalendarStrip
   ref={calendarRef}
   calendarAnimation={{type: 'sequence', duration: 30}}
   style={styles.calendarStrip}
   onDateSelected={onDateChange}
/>
)

You need to add scrollable={true} to your code. like this
<CalendarStrip
ref={calendarRef}
scrollable={true}
calendarAnimation={{type: 'sequence', duration: 30}}
style={styles.calendarStrip}
onDateSelected={onDateChange}
/>

Thanks @tanyicheng. It's helped