react-native-calendario icon indicating copy to clipboard operation
react-native-calendario copied to clipboard

Unable to rerender component after changing minDate or startingMonth props

Open oguzhanturgut opened this issue 3 years ago • 8 comments

Is there any way to force calender rerender after changing one of its props?

oguzhanturgut avatar Aug 18 '20 11:08 oguzhanturgut

I am trying to control component from screen but coul not manage to. Calendar does not rerender after changing props

const CalenderPicker = ({calendarProps}) => {

  const {minDate, maxDate, startingMonth} = calendarProps;

  return (
    <Calendar
      onChange={range =>
        console.log({
          startDate: moment(range.startDate).utc(),
          endDate: moment(range.endDate ?? range.startDate).utc(),
        })
      }
      minDate={minDate}
      maxDate={maxDate}
      startingMonth={startingMonth}
      numberOfMonths={13}
      // initialListSize={13}
      firstDayMonday
      showWeekdays={false}
      theme={THEME}
    />
  );
};

oguzhanturgut avatar Aug 18 '20 13:08 oguzhanturgut

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Oct 17 '20 14:10 stale[bot]

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

stale[bot] avatar Oct 24 '20 19:10 stale[bot]

I'm having this same issue also. I'm using Expo and Next.js, trying to create a calendar component with switchable months (because react-native-calendars wasn't cooperating). I'm rendering one month at a time, and then when the user presses the button, it switches to the next month. The logic is all working correctly, but the startingMonth prop isn't changing or even working when I set it manually.

ztcollazo avatar Apr 26 '22 20:04 ztcollazo

I'm having this same issue also. I'm using Expo and Next.js, trying to create a calendar component with switchable months (because react-native-calendars wasn't cooperating). I'm rendering one month at a time, and then when the user presses the button, it switches to the next month. The logic is all working correctly, but the startingMonth prop isn't changing or even working when I set it manually.

You could try react-native-month instead

maggialejandro avatar May 10 '22 19:05 maggialejandro

Thanks, I'll check this out. If it doesn't work, then we'll know that it's a problem with react-native-month, so I'll just open an issue there instead.

ztcollazo avatar May 10 '22 19:05 ztcollazo

Yep, It worked. I did have to do a bit of fiddling to figure it out, so for anyone looking to do this in the future: having a state variable date and then changing date and using getMonth and getFullYear doesn't work (which is a React thing, not a react-native-month thing). Instead, you need to have two separate state variables (eg: month and year) and use those.

ztcollazo avatar May 11 '22 20:05 ztcollazo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Jul 10 '22 21:07 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Sep 20 '22 19:09 stale[bot]

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

stale[bot] avatar Oct 01 '22 02:10 stale[bot]