0

Using the calendarList , onVisibleMonthsChange={this.loadItems} does not update markedDates

My loadItems function is:

loadItems(months) {
    const { events, eventsForMonth } = this.props;

    eventsForMonth(events, months);
}
        <CalendarList
            style={styles.calendar}
            current={currentDate}
            markingType={"multi-dot"}
            onVisibleMonthsChange={this.loadItems}
            onDayPress={this.onDayPress}
            minDate={currentDate}
            loadingIndicatorColor={"#6da1a6"}
            markedDates={eventsMonth}
            pastScrollRange={0}
            futureScrollRange={6}
            scrollEnabled={true}
            showScrollIndicator={true}
        />

I create my events for each month using the reducer below, on initial render, I create my own timestamp for the loop:

export function eventsForMonth(state = {}, action) {
    switch (action.type) {
        case "EVENTS_CALENDAR_MONTH": {
            const { data, day } = action;
            if (!day) {
                const currentDate = helpers.currentDate;
                const timestamp = Date.parse(currentDate);
                const day = [{
                    timestamp
                }]
            }
            const newItems = {};

            for (let i = -15; i < 20; i++) {
                const time = day[0].timestamp + i * 24 * 60 * 60 * 1000;

                const strTime = timeToString(time);

                if (data[strTime]) {
                    newItems[strTime] = { ...data[strTime] };
                } else {
                    newItems[strTime] = {};
                }
            }
            return {
                ...newItems
            };
        }
        default:
            return state;
    }
}

My eventsMonth after scrolling is showing the correct data in the correct format, how come my month doesn't render?

{
  "2018-11-24": {},
  "2018-11-25": {},
  "2018-11-26": {},
  "2018-11-27": {},
  "2018-11-28": {},
  "2018-11-29": {},
  "2018-11-30": {},
  "2018-12-01": {
    "dots": [
      {
        "id": 2983,
        "title": "Kiranjit Event",
        "colour": "",
        "textColor": "#000000",
        "organiser": "N/A",
        "description": "",
        "selectedDotColor": "",
        "categories": [
          {
            "name": "Student 1 - Kiranjit Aujla",
            "slug": "student-1-spc",
            "term_group": 0,
            "term_taxonomy_id": 107,
            "taxonomy": "tribe_events_cat",
            "description": "",
            ...
          }
        ],
        "startTime": "08-00",
        "endTime": "17-00"
      }
    ],
    "disabled": false,
    "selected": true,
    "selectedColor": "#00CCCB",
    "customStyles": {
      "text": {
        "marginTop": 3
      }
    }
  },
  "2018-12-02": {},
  "2018-12-03": {}
}
Bomber
  • 10,195
  • 24
  • 90
  • 167
  • As you said `eventsMonth` is showing correct data, but have you refreshed your view or rerendered it after getting data in that variable? Because `onVisibleMonthsChange` is just a callback, it will not refresh the calendar. As you can see `markedDates={eventsMonth}` is the props to pass current months data, you are having that data in variable but it is not passed to ``. So you just need to refresh the control buy `this.setState({})` and it should work. – Ravi Aug 30 '18 at 09:21
  • No, how would I do that? I'm using `redux` – Bomber Aug 30 '18 at 09:30
  • Not sure but write `this.setState({})` after `eventsForMonth(events, months);` – Ravi Aug 30 '18 at 09:31
  • tried that, still no luck – Bomber Aug 30 '18 at 09:42

0 Answers0