【问题标题】:`object` supplied to `ReactiveComponent`, expected `function`提供给“ReactiveComponent”的“object”,预期的“function”
【发布时间】:2019-06-27 09:54:49
【问题描述】:

我在尝试将 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;
  };

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

【问题讨论】:

    标签: javascript reactjs reactivesearch


    【解决方案1】:

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

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

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

    v3 : https://codesandbox.io/s/serene-ritchie-rjo3m

    v2 : https://codesandbox.io/s/tender-ramanujan-f3g31

    希望这会有所帮助!

    【讨论】:

    • 一些修改,但有帮助
    猜你喜欢
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    • 2018-01-23
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多