Reputation: 11
I've implemented react-datepicker
in one of my projects. I'm filtering out my data based on the selected month from the react-datepicker
.
I want to call a function when I select a date that I am able to successfully use in the onChange
? method.
The same way I want to call a function when I clear the date using the cross icon in the isClearable method on the date picker component.
Is there any way I can call a function on isClearable
?
Thanks :)
I am attaching the react-datepicker
code I'm using in my code and also a function that I want to call when I deselect the date in the datepicker component.
const testFun = () => {
console.log("Function calling works on isClearable");
anotherFunCall();
}
<DatePicker
selected={monthYear}
dateFormat="yyyy/MM"
// minDate={}
maxDate={new Date()}
onChange={(date) => {
setMonthYear(date);
setHide1(false);
}}
placeholderText="YYYY-MM"
showMonthYearPicker
dropdownMode="select"
isClearable={testFun}
/>
Upvotes: 1
Views: 1481
Reputation: 11
I have resolved my issue by using calling the function in an if statement with the state as the condition on which i was storing my date. So whenever the data in state clears the function gets called. :)
Upvotes: -1