function runs when click on date react native calendar strip
Function Runs When Click on Date React Native Calendar Strip
If you are using React Native Calendar Strip in your project, you might want to know how to execute a function when the user clicks on a date. Here are two ways you can do it:
1. Using the 'onDateSelected' prop
The first and easiest way to execute a function when the user clicks on a date in React Native Calendar Strip is by using the 'onDateSelected' prop. This prop is invoked whenever the user selects a date, and it returns the selected date as a moment object.
<CalendarStrip
onDateSelected={(date) => {
// Execute your function here
}}
/>
In the above code snippet, we have added the 'onDateSelected' prop to the CalendarStrip component, and passed a function as its value. Inside this function, you can write your code that needs to be executed when the user selects a date.
2. Using the 'onWeekChanged' prop
The second way to execute a function when the user clicks on a date is by using the 'onWeekChanged' prop. This prop is invoked whenever the user changes the week, and it returns an array of moment objects representing the dates in the current week.
<CalendarStrip
onWeekChanged={(weekDates) => {
// Extract the selected date from weekDates array and execute your function here
}}
/>
In the above code snippet, we have added the 'onWeekChanged' prop to the CalendarStrip component, and passed a function as its value. Inside this function, you can extract the selected date from the 'weekDates' array and execute your code accordingly.