首页 > 解决方案 > TypeError: __webpack_require__.i(...) 不是 React-Select 中的函数

问题描述

我正在使用react-select插件从下拉列表中进行多项选择。

对于安装我已经完成

npm install react-select --save

其中安装了最新版本 3.0.4 的 react-select 插件

我的代码是

import React, { Component } from 'react';
import Select from 'react-select';

import urls from '../../../urls.json';

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' },
];
class Reports extends Component {

  constructor(props) {
    super(props);

    this.state = {
      selectedOption: null,
    };

  }
  handleChange = selectedOption => {
    this.setState({ selectedOption });
    console.log(`Option selected:`, selectedOption);
  };
  componentDidMount() { }

  render() {

    return (
      <div>
        <div className="row">
          <div className="col-md-12">
            <h2>Reports</h2>
            <hr className="title-separator" />
            <Select
                value={this.state.selectedOption}
                onChange={this.handleChange}
                options={options}
            />
          </div>
        </div>
      </div >
    )
  }
}

export default Reports;

在此处输入图像描述

请帮忙!

标签: reactjsreact-select

解决方案


您使用的版本react-select与您的react. react-select您可以通过执行以下操作降级以使用 v2:

npm install react-select@2.4.4

有关升级的更多详细信息,请参阅v3 升级指南


推荐阅读