2016-11-15 5 views
0

datePickerAndroidを使用して以降の状態を設定しようとすると、このエラーが発生します。TypeError:予想される動的タイプ 'double' 'type' string '

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にそれを絞り込むきた、と私は初期状態に文字列を作るだけでなく、単純な文字列に状態を設定するが、まだエラーを取得しようとしました。言い換えればDatePickerAndroid

expected dynamic type double

については

+0

ミリ秒が予想されますか?newDate.getTime()? – jcuenod

+0

これはどのコード行ですか? – wallyk

+0

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

答えて

0

ネイティブコンポーネントは、時間を望んでいるが、あなたは、文字列を置きます。 this.props.startDateは文字列で、時刻を時刻形式で転送します。例:

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

幸運!

関連する問題