首页 > 解决方案 > 提供给“ReactiveComponent”的“object”,预期的“function”

问题描述

尝试将 ReactiveSearch 用于搜索栏时出现此错误。这就是我初始化它的方式:

render() {
    const { tenantConfig, size, componentId } = this.props;
    return (
      <ReactiveComponent
        componentId={componentId}
        defaultQuery={this.defaultQuery}
      >
        <SearchDropdownDashboard
          size={size}
          handleSearchDashboard={this.handleSearchDashboard}
          fetching={this.state.fetching}
          tenantConfig={tenantConfig}
        />
      </ReactiveComponent>
    );
  }

这是传入的函数:

defaultQuery = () => {
    const { dashboardText } = this.state;
    const { mustNotObj } = this.props;

    let obj;

    obj = {
      query: {
        bool: {
          must_not: mustNotObj,
          must: multiMatchSearch(dashboardText)
        }
      },
      from: 0,
      size: 20
    };

    return obj;
  };

关于我在这里做错了什么有什么建议吗?该函数似乎已正确传递给组件。

标签: javascriptreactjsreactivesearch

解决方案


如果您正在使用v3,那么这是由于最近在 API 中引入的更改。您将需要使用renderprop 或 React 渲染模式,如下例所示。

您可以在此处查看文档:https ://opensource.appbase.io/reactive-manual/advanced/reactivecomponent.html#usage-with-defaultquery 。

我在两个版本上都创建了使用 ReactiveComponent 的示例:

v3https ://codesandbox.io/s/serene-ritchie-rjo3m

v2https ://codesandbox.io/s/tender-ramanujan-f3g31

希望这可以帮助!


推荐阅读