0

react-datepicker我已经完成了软件包的基本设置并且它正在工作。但是,在我们的应用程序中,我们也在使用events-polyfillpackage.json 。而当这两个包同时使用时,react-datepicker就不能正常工作了。

import React from "react";
import ReactDOM from "react-dom";
import DatePicker from "react-datepicker";
import "events-polyfill";

import "react-datepicker/dist/react-datepicker.css";
import "./styles.css";

function App() {
  return <Example />;
}

// CSS Modules, react-datepicker-cssmodules.css
// import 'react-datepicker/dist/react-datepicker-cssmodules.css';

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      startDate: new Date()
    };
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(date) {
    this.setState({
      startDate: date
    });
  }

  render() {
    return (
      <DatePicker
        selected={this.state.startDate}
        onChange={this.handleChange}
      />
    );
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

演示:https ://codesandbox.io/s/pj3yl7o0wm

完整错误:

Uncaught TypeError: Cannot read property 'once' of null
    at Object.module.exports.EventListenerInterceptor.normalizeListenerOptions (index.js:111)
    at Object.module.exports.EventListenerInterceptor.normalizeListenerArguments (index.js:122)
    at HTMLDocument.target.addEventListener (index.js:161)
    at react-onclickoutside.es.js:226
    at Array.forEach (<anonymous>)
    at onClickOutside._this.enableOnClickOutside (react-onclickoutside.es.js:225)
    at onClickOutside.componentDidMount (react-onclickoutside.es.js:296)
    at commitLifeCycles (react-dom.development.js:14362)
    at commitAllLifeCycles (react-dom.development.js:15463)
    at HTMLUnknownElement.callCallback (react-dom.development.js:100)

这在events-polyfill index.js文件中突出显示为罪魁祸首:

options.once      = Boolean(options.once);

完全不知道是什么问题。

4

1 回答 1

1

尝试更新 events-polyfill 包。

看起来当前版本https://github.com/lifaon74/events-polyfill/blob/master/src/EventListenerInterceptor.js#L105对这种情况进行了修复。

这是带有修复的提交https://github.com/lifaon74/events-polyfill/commit/a087bf90e2335cdad670d08499157c40ea73abdb它针对 2.1.1 但 npm 只有 2.1.0

从特定版本的 Git 安装 npm

于 2019-03-15T09:05:35.477 回答