似乎无法弄清楚如何修复 React Dates 而不破坏每次不同的东西
我有这个:
const [startDate, setStartDate] = useState(moment().subtract(2, 'year'))
const [endDate, setEndDate] = useState(null)
const [focusedInput, setFocusedInput] = useState('startDate')
const onDatesChange = ({ startDate, endDate }) => {
setStartDate(startDate)
setEndDate(endDate)
}
<DateRangePicker
endDate={endDate}
endDateId="endDate"
focusedInput={focusedInput.focusedInput}
isOutsideRange={() => null}
onDatesChange={onDatesChange}
onFocusChange={(focusedInput) => setFocusedInput({ focusedInput })}
startDate={startDate}
startDateId="startDate"
/>
所以我得到的第一个错误是这样的:Uncaught Error: Objects are not valid as a React child (found: object with keys {_isAMomentObject, _isUTC, _pf, _locale, _d, _isValid})
然后我尝试了各种类似这样的东西:
const onDatesChange = ({ startDate, endDate }) => {
setStartDate(moment(startDate).format('DD-MM-YYYY')
setEndDate(moment(endDate).format('DD-MM-YYYY)
}
并将初始状态设置为 null。但后来这给了我一个错误invalid date
我想做的就是在一个范围内设置2个不同的日期,这似乎非常复杂
人到中年有点甜
相关分类