2016-11-15 118 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! 
    }); 

祝你好運!

相關問題