React-select 组件不工作
React-select component not working
我正在尝试使用 react-select component. I have the normal version working absolutely fine, but when I add try to use 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 代码中,但我终其一生都无法弄清楚发生了什么。
这是我的完整组件代码,用于具有上述异步 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;
问题似乎出在 Select.Async
行中的“.Async”扩展名,这会不会混淆 Meteor?
我找出问题所在:从 npm 安装当前安装版本 0.9.x,但是文档和示例已经更新到版本 1.0.0-betaX,其中有重大更改。
所以,Select.Async
确实是问题所在,该语法仅从 1.0 开始存在,作为 react-select github 存储库中的 discussed in this list of breaking changes in 1.0.0。更新我的代码以使用 1.0.0-beta9 版本解决了这个问题。
我正在尝试使用 react-select component. I have the normal version working absolutely fine, but when I add try to use 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 代码中,但我终其一生都无法弄清楚发生了什么。
这是我的完整组件代码,用于具有上述异步 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;
问题似乎出在 Select.Async
行中的“.Async”扩展名,这会不会混淆 Meteor?
我找出问题所在:从 npm 安装当前安装版本 0.9.x,但是文档和示例已经更新到版本 1.0.0-betaX,其中有重大更改。
所以,Select.Async
确实是问题所在,该语法仅从 1.0 开始存在,作为 react-select github 存储库中的 discussed in this list of breaking changes in 1.0.0。更新我的代码以使用 1.0.0-beta9 版本解决了这个问题。