React-native: [DatePickerIOS] Warnings failed propType unexpected

Created on 3 Mar 2016  路  13Comments  路  Source: facebook/react-native

I'm currently trying out the DatePickerIOS and this simple example throws two warnings :


constructor(props) {
  super(props);

  this.state = {
    timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
    date: new Date(),
    color: '#007AFF',
    minimumDate: this.props.minimumDate,
  }
}

onDateChange = (date) => {
  this.setState({date: date});
};

render () {
  return (
    <View style={styles.basicContainer}>
      <DatePickerIOS
        date={this.state.date}
        mode="datetime"
        timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours}
        onDateChange={() => this.onDateChange}
        minimumDate={this.state.minimumDate}
       />
    </View>
  );
};

I'm getting these warnings :

2016-03-03 09:32:58.829 [warn][tid:com.facebook.React.JavaScript] Warning: Failed propType: Invalid prop `date` of type `Number` supplied to `RCTDatePicker`, expected instance of `Date`. Check the render method of `DatePickerIOS`.
2016-03-03 09:32:58.830 [warn][tid:com.facebook.React.JavaScript] Warning: Failed propType: Required prop `onDateChange` was not specified in `RCTDatePicker`. Check the render method of `DatePickerIOS`.

I did aconsole.log(this.props) in react-native's file DatePickerIOS.ios.js in Libraries/Components and the output is the following :

{ date: Thu Mar 03 2016 09:32:58 GMT+0100 (CET),
  mode: 'datetime',
  timeZoneOffsetInMinutes: 1,
  onDateChange: [Function],
  minimumDate: undefined }

Any chances I'm doing this wrongly ?

Help Wanted iOS Ran Commands Locked

Most helpful comment

I'm still having the warning. Why is the pull request closed?

All 13 comments

+1 Getting the same error.

@facebook-github-bot label iOS

@ghamaide - seems like a bug! if someone can investigate this it would be appreciated. It's worth trying the DatePickerIOS example in UIExplorer and ensuring that works as expected without warnings, if not then use that as the test case to fix.

image

because of requireNativeComponent, the RCTDatePickerIOS will be verify props base on the DatePickerIOS.propTypes.

but using RCTDatePickerIOS in the DatePickerIOS#render() was wrong, the date is number, undefined the onChange

Good discovery @epooren - that makes a lot of sense.

image

i fixed it at my branch

Would you mind opening a Pull Request with your changes? It'd be great to introduce a solution to this!

I'm still having the warning. Why is the pull request closed?

I implemented the pull request changes in my DatePickerIOS.ios.js and it didn't solve the problem. I now get:

JSON value '2016-05-17 20:24:59 +0000' of type NSDate cannot be converted to a date

Any other ideas how to make the DatePickerIOS component work?
I'm on react-native v0.24.1

@brentvatne If I make a pr so that datePicker can accept both a Number or a Date object and check the date to see if it can getTime would that be fine? This way the verification at the native level will be fine with the number

+1

Just started using the picker and also having the warning.

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/datepickerios-warnings-failed-proptype-unexpected

Product Pains has been very useful in highlighting the top bugs and feature requests:
https://productpains.com/product/react-native?tab=top

Also, if this issue is a bug, please consider sending a pull request with a fix.

Was this page helpful?
0 / 5 - 0 ratings