javascriptreactjsreactivesearch

`object` supplied to `ReactiveComponent`, expected `function`


I'm getting this error when trying to use ReactiveSearch for a search bar. This is how I'm initialising it:

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>
    );
  }

And this is the function that is being passed in:

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;
  };

Any suggestions as to what I'm doing wrong here? The function seems to be passed correctly to the component.


Solution

  • If you are using v3, then it is due to the recent changes introduced in API. You will need to use render prop or React render Pattern as done in the below example.

    You can check the docs here: https://opensource.appbase.io/reactive-manual/advanced/reactivecomponent.html#usage-with-defaultquery.

    I have created the example of Usage of ReactiveComponent on both the versions:

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

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

    Hope this helps!