I would like to styles the background of previous days according to the current date.
I'm trying to follow this example here, but I get the error:
Invariant Violation: React.Children.only expected to receive a single React element child.
Which is crazy, because it works in the example. Also, there is no information about the dateCellWrapper
in the docs, which doesn't help much.
Here is the code:
const ColoredDateCellWrapper = (children: any, value: any) =>
React.cloneElement(Children.only(children), {
style: {
...children.style,
backgroundColor: value < this.state.currentDay ? 'lightgreen' : 'lightblue',
},
});
<BigCalendar
showMultiDayTimes
localizer={localizer}
selectable
selected={this.state.selected}
onSelectEvent={this.onSelectEvent}
onSelectSlot={this.onSelectSlot}
events={this.state.events}
step={60}
timeslots={1}
defaultView='week'
startAccessor="start"
endAccessor="end"
defaultDate={new Date()}
components={{
dateCellWrapper: ColoredDateCellWrapper
}}
/>
Thank you! :)