stephy / CalendarPicker

CalendarPicker Component for React Native
803 stars 373 forks source link

CalendarPicker selectedStartDate #165

Closed jordyortega closed 4 years ago

jordyortega commented 5 years ago

I have a button seperate from the calendarPicker which can go to the next day and previous day. so today is 2019-9-21. If I click the button it goes to 2019-9-22, then to 23 and so on.

How do I update the CalendarPicker to have the prop selectedStartDate as the date I have chosen seperated from CalendarPicker?

Because if I do this:

                    <CalendarPicker
                        ref={ref => {
                            this.calendarPicker = ref;
                        }}
                            onDateChange={(date) => this.goToDate(date)}
                            selectedStartDate={this.state.selectedDate}
                    />

I get Maximum state update error.

peacechen commented 4 years ago

It looks like changing the selectedStartDate prop triggers the onDateChange callback. If your goToDate() method updates state.selectedDate, it would trigger another cycle and loop forever. You should put logic in your goToDate() which checks whether the date is the same, and not update state if that's the case.