日期选择器React中的无效时间值

时间:2019-09-03 11:58:30

标签: javascript reactjs react-datepicker

当我从日期选择器中选择一个日期时,我想在Item组件console.log(this.props.endDate)中显示它,出现错误“范围无效时间”。我使用:https://www.npmjs.com/package/react-datepicker

class App extends Component {
  constructor() {
    super();
    this.state = {
      endDate: new Date()
    };
  }

  handle = (date) => {
    this.setState({
      endDate: date
    })
  }

  render() {
    return (
      <div>
        <Item
          endDate = {this.state.endDate}
          handle = {this.handle}
        />
      </div>
    );
  }
}

class Item extends Component {
  constructor() {
    super();

  }

  render() {
    console.log(this.props.endDate)
    return (
      <div>
        <DatePicker
          selected={this.props.endDate}
          onChange={this.props.handle()}
          showTimeSelect
          timeFormat="HH:mm"
          timeIntervals={15}
          dateFormat="MMMM d, yyyy h:mm aa"
          timeCaption="time"
        />
      </div>
    );
  }
}

0 个答案:

没有答案