React-select组件不起作用

时间:2016-02-16 18:57:40

标签: 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}
/>

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

  

警告:React.createElement:type不应为null,未定义,   布尔值或数字。它应该是一个字符串(对于DOM元素)或a   ReactClass(用于复合组件)。检查渲染方法   OrderHeaderEdit

我一直试图将其调试到React代码中,但我不能为我的生活找出正在发生的事情。

这是我上面有async select组件的组件的完整组件代码。此控件在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;

似乎问题可能是&#39; .Async&#39; Select.Async行的扩展,这会让Meteor感到困惑吗?

1 个答案:

答案 0 :(得分:2)

我解决了问题所在:从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版本解决了这个问题。