BugiDev / react-native-calendar-strip

Easy to use and visually stunning calendar component for React Native.
MIT License
933 stars 325 forks source link

selectedDate prop should also execute same behavior as onDateSelected #292

Closed sparshag007 closed 3 years ago

sparshag007 commented 3 years ago

selectedDate prop lets you select the default date when the calendar-strip is rendered. eg: selectedDate={moment()} selects the current date by default.

onDateSelected prop lets you execute a function or define a behavior as to what should happen when user selects a date eg: onDateSelected={(selectedDate)=>{ alert('Hello People')} } displays an alert when date is selected

The problem lies here is when the component is rendered , the selectedDate should also display an alert as it should execute the same behavior as onSelectedDate

Is there a way to do it?

peacechen commented 3 years ago

The onDateSelected callback is intended to fire when the user selects a date. It specifically does not fire when the selectedDate prop changes because that can easily lead to infinite loops: selectedDate change -> onDateSelected fires and sets selectedDate state -> selectedDate change... That scenario can happen even if the date value is the same but its underlying object changes (e.g. a date clone).

As the consumer of this library, you know exactly when you change selectedDate's value. Your code should detect that and take the appropriate action.