react-native-calendars: ref stopped working sometimes after version
I used to be able to pass a ref to calendar and extract some data for example like this calendarRef.current?.state.currentMonth
.
In the recent versions of the library, the ref just returns undefined.
Expected Behavior
Expect to be able to get the ref of the calendar
Environment
Please run these commands in the project folder and fill in their results:
react-native-calendars version: 1.1282.0 react-native version: 0.65.1
Here is some simple code that already fails to get the ref.
const calendarRef = useRef<Calendar>(null);
<Calendar
ref={calendarRef}
...
/>
And we can even do something like this, and the inner ref comes back as undefined
<Calendar
ref={ref => console.log('Ref is', ref)}
...
/>
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 32
Having a similar issue with trying to add a reference to AgendaList and calling
agendaListRef.current.chooseDay()
@KrisLau Yes, you can’t scroll to an item that was not rendered, but the AgendaList’s scroll is handled by the ExpandableCalendar (that’s the whole point), you should not manage it yourself. If you need to change the date, change it in the CalendarProvider’s
date
prop and the date should change in both the calendar and agenda list.