meteor - React-select 组件不工作

标签 meteor reactjs react-select

我正在尝试使用 react-select component 的异步版本。我的普通版本工作得很好,但是当我添加时尝试使用 this async example from the project documentation:

var Select = require('react-select');

var getOptions = function(input, callback) {
    setTimeout(function() {
        callback(null, {
            options: [
                { value: 'one', label: 'One' },
                { value: 'two', label: 'Two' }
            ],
            // CAREFUL! Only set this to true when there are no more options,
            // or more specific queries will not be sent to the server.
            complete: true
        });
    }, 500);
};

<Select.Async
    name="form-field-name"
    loadOptions={getOptions}
/>

我在控制台中收到此错误:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of OrderHeaderEdit.

我一直在尝试将其调试到 React 代码中,但我一生都无法弄清楚发生了什么。

这是我的完整组件代码,该组件具有上面的异步选择组件。该控件正在 Meteor 1.3 应用程序中运行:

import React from 'react';
import Select from 'react-select';

const OrderHeaderEdit = React.createClass({

    getOptions(input, callback) {
        setTimeout(function () {
            callback(null, {
                options: [
                    { value: 'one', label: 'One' },
                    { value: 'two', label: 'Two' }
                ],
                // CAREFUL! Only set this to true when there are no more options,
                // or more specific queries will not be sent to the server.
                complete: true
            });
        }, 500);
    },

    render() {
        console.log("OrderHeaderEdit props: ", this.props);

        var getOptions = function (input, callback) {
            setTimeout(function () {
                callback(null, {
                    options: [
                        { value: 'one', label: 'One' },
                        { value: 'two', label: 'Two' }
                    ],
                    // CAREFUL! Only set this to true when there are no more options,
                    // or more specific queries will not be sent to the server.
                    complete: true
                });
            }, 500);
        };

        return (
            <div>

                <Select.Async
                    name="form-field-name"
                    loadOptions={getOptions}
                />

            </div>
        );
    }
});

export default OrderHeaderEdit;

看来问题可能出在 Select.Async 行中的“.Async”扩展名,这会让 Meteor 感到困惑吗?

最佳答案

我找出了问题所在:从 npm 安装当前安装版本 0.9.x,但文档和示例已更新到版本 1.0.0-betaX,该版本具有重大更改。

因此,Select.Async 确实是问题所在,该语法仅从 1.0 开始存在,如 discussed in this list of breaking changes in 1.0.0来自react-select github 存储库。更新我的代码以使用 1.0.0-beta9 版本解决了该问题。

关于meteor - React-select 组件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35440833/

相关文章:

reactjs - react 警告 : "is changing an uncontrolled input of type hidden to be controlled" why?

reactjs - React Select - 如何显示/迭代选项中 api 调用的数据而不是硬编码选项?

javascript - 如何在 react 选择组件上添加图标和工具提示?

meteor 错误 : Cannot find module '@babel/runtime/helpers/builtin/interopRequireDefault'

javascript - MongoDB 根据日期更新变量

从命令行使用时 meteor 登录失败

reactjs - 需要 react 选择下拉列表

javascript - Meteor.js 最有用的智能包是什么

html - 使用 styled-components 覆盖 material-ui 按钮样式

javascript - 如何在 parent 调整大小时重新呈现 react-grid-layout 列的宽度?