react-datepicker
我已经完成了软件包的基本设置并且它正在工作。但是,在我们的应用程序中,我们也在使用events-polyfill
package.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);
完全不知道是什么问题。