问题
I have the following in my Calendar component JSX:
components={{
dateCellWrapper: ({children, value}) =>
React.cloneElement(Children.only(children), {
style: {
...children.style,
backgroundColor: calendarDest.map((x,i) =>
moment(value).add('days', 1).isBetween(x.dtArrive,x.dtDepart)?
colors[i]: 'white'),
opacity: .25
},
})
}}
It is inside a stateless functional component.
I have calendarDest
, above, updating into the state via a useEffect
hook that updates the state every time the props change.
The calendar component's state updates properly, but the children accessed in components={{...}}
only ever reflect the initial state of the parent component.
来源:https://stackoverflow.com/questions/57697916/react-big-calendar-component-children-not-updating-on-state-update