Sometimes, I want to pass a second argument to a function, but sometimes I don't pass the second argument.
Below is my method:
const updateStartEnd = (newEndDate: any, newStartDate: any) => {
if (prevDate && newStartDate && newStartDate.isBefore(prevDate, 'd')) {
setEndDate(newStartDate);
} else {
setEndDate(newEndDate);
}
};
I call this function like below:
const some_function = (newDates: {startDate, endDate}) => {
if (endDate !== null) {
updateStartEnd(endDate, startDate);
} else {
updateStartEnd(endDate, startDate); //here i dont want to pass startDate as it will not need to check for if condition in the updateStartEnd.
}
}
Could someone help me with this?