I have an array of dates in "MM/DD/YYYY" format. But passing this array via the hightlightDates
prop to react-datepicker
is not highlighting the days on the calendar. How can I accomplish this?
<DatePicker
showIcon
selected={startDate}
customInput={<CustomInput />}
onChange={(date) => setStartDate(date)}
minDate={new Date()}
highlightDates={[datesWithEvent]}
wrapperClassName="calendar-wrapper"
calendarClassName="calendar"
className="datepicker"
/>
2
Answers
DatePicker
expects an array of dates. You are passing an array or arrays of dates. Remove the ‘[‘, ‘]’ should work.As can be read inside the documentation here you need to pass an array of
Date
objects rather than strings to thehighlightDates
prop. The example is using thesubDays
method from date-fns.Please note that you should do some research on your own before posting to StackOverflow. A look at the library documentation would’ve probably sufficed.