如何让 DateRangePicker 在点击时呈现日历?

How can I get DateRangePicker to render calendars on click?

当我在 webpack-dev-server 中呈现它时,日历不会在点击时呈现。

如果我尝试手动更改日期,我会收到错误消息:

DateSelection.js?f52c:25 Uncaught TypeError: Cannot read property 'calendarFocus' of null

SingleDatePicker 似乎工作得很好,但 DateRangePicker 不行。我该怎么做才能在点击时正确呈现日历?

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import moment from 'moment';
import { DateRangePicker } from 'react-dates';
import 'react-dates/initialize';
import 'react-dates/lib/css/_datepicker.css';

class DateSelection extends Component {
  constructor(props) {
    super(props);
    this.state = {
      startDate: moment(),
      endDate: moment(),
      calendarFocus: 'startDate',
    }
    this.onDatesChange = this.onDatesChange.bind(this);
    this.onFocusChange = this.onFocusChange.bind(this);
    this.onSubmit = this.onSubmit.bind(this);
  };

  onDatesChange({ startDate, endDate }) {
    this.setState(() => ({ startDate, endDate }));
  };

  onFocusChange({ calendarFocus }) {
    this.setState(() => ({ calendarFocus }));
  };

  onSubmit(e) {
    e.preventDefault();
    console.log(this.state);
  };

  render() {
    return (
      <form onSubmit={this.onSubmit}>
        <DateRangePicker
          startDate={this.state.startDate}
          startDateId="startDate"
          endDate={this.state.endDate}
          endDateId="endDate"
          onDatesChange={this.onDatesChange}
          focusedInput={this.state.calendarFocus}
          onFocusChange={this.onFocusChange}
        />
        <br/>
        <input type="submit" value="Submit" />
      </form>
    );
  }
};

ReactDOM.render((
  <DateSelection/>
), document.getElementById('root'));

其他详情:

此外,顺便说一句,我似乎找不到 react-dates 的当前文档。很多地方link我到this storybook,但似乎缺少一些信息。例如这里的描述栏是空白的。

尝试在构造函数中将 calendarFocus 设置为 null

并改变

onFocusChange({ calendarFocus }) {
  this.setState(() => ({ calendarFocus }));
};

onFocusChange(calendarFocus) {
  this.setState(() => ({ calendarFocus }));
};