Why highlightDates property changes doesn't trigger component update?
I have dynamic highlightDates array, after i update it, nothing happens, but should add some class to defined dates.
<DatePicker
inline
monthsShown={2}
highlightDates={dates}
I was wondering the same thing here. I need it to update as i have selected one date. Anyone got any clues about it?
I got one solution, not perfect, but working.
First, need to add ref to second datepicker:
<DatePicker inline monthsShown={2} ref={secondDatepickerRef} />
Then you can manipulate with component reference:
const dates = [format(new Date('2019-03-25'), 'MM.DD.YYYY')];
const highlightedDates = new Map();
dates.forEach(el => newMap.set(el, ['react-datepicker__day--highlighted']));
secondDatepickerRef.state.highlightDates = highlightedDates;
highlightDates should be Map instance, where first argument is a date and second - highlighted class.
I got one solution, not perfect, but working.
First, need to add ref to second datepicker:
<DatePicker inline monthsShown={2} ref={secondDatepickerRef} />Then you can manipulate with component reference:
const dates = [format(new Date('2019-03-25'), 'MM.DD.YYYY')]; const highlightedDates = new Map(); dates.forEach(el => newMap.set(el, ['react-datepicker__day--highlighted'])); secondDatepickerRef.state.highlightDates = highlightedDates;highlightDates should be Map instance, where first argument is a date and second - highlighted class.
This worked for me, thank you @demkovych. :+1:
And if you want to update datepicker, you can call:
secondDatepickerRef.handleFocus()
Possibly cleaner and less breaking for React - add a key property to the datepicker - this will force it to update itself.
key={shortid.generate()}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Possibly cleaner and less breaking for React - add a key property to the datepicker - this will force it to update itself.
key={shortid.generate()}