尝试使用datePickerAndroid
并在之后设置状态时遇到此错误。
我觉得问题可能来自初始状态为new Date()
但不是100%确定。
_isAndroid = async () => {
let {action, year, month, day} = await DatePickerAndroid.open({
date: this.props.startDate,
});
if (action === DatePickerAndroid.dismissedAction) {
this.props.closeModal()
} else {
const date = year + "-" + month + "-" + day
this.props.onDateChange(date)
}
}
Prop Function:
onDateChange = (newDate) => {
this.setState({currentDate: newDate}) // <- This one is breaking
let dates = this.state.dates;
let index = this.state.currentIndex;
if (this.state.currentKey === "start") {
dates[index].start = newDate
} else {
dates[index].end = newDate
}
this.setState({dates: dates});
}
我已将其缩小到第一个setState
,我已尝试将初始状态设为字符串,并将状态设置为简单字符串但仍然出错。
答案 0 :(得分:0)
对于DatePickerAndroid
预期的动态类型双
换句话说,本机组件需要时间,但是你放了字符串。你this.props.startDate是字符串,传输时间格式。例如:
const {action, year, month, day} = await DatePickerAndroid.open({
date: new Date() // <- This is Date, not string!
});
祝你好运!