我正在尝试使用 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/