2016-11-15 69 views
0

我试图使用datePickerAndroid并在之后设置状态时遇到此错误。TypeError:预期的动态类型'双',但有类型'字符串'

Error Message

我觉得这个问题可能是从初始状态是一个肯定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

它是否期望毫秒:'newDate.getTime()'? – jcuenod

+0

哪行代码是? – wallyk

+0

'this.setState({currentDate:newDate})' – jcuenod

回答

0

对于DatePickerAndroid

expected dynamic type double

换句话说机组件想要的时间,但你把字符串。你this.props.startDate是字符串,传输时间格式。例如:

const {action, year, month, day} = await DatePickerAndroid.open({ 
    date: new Date() // <- This is Date, not string! 
    }); 

祝你好运!

相关问题