javascript - 提供给“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;
};
关于我在这里做错了什么有什么建议吗?该函数似乎已正确传递给组件。
解决方案
如果您正在使用v3
,那么这是由于最近在 API 中引入的更改。您将需要使用render
prop 或 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
希望这可以帮助!
推荐阅读
- go - 如何使用 gorm 解决“运行时错误:无效的内存地址或 nil 指针取消引用”
- python - 在 Python 中创建赛车,为什么我的车没有赛车?
- java - Java - Base64 解码
- r - 在 r 中绘制两个 sf POINT 特征之间的线
- c# - 如何使用 sqlite 数据库部署 C# WPF 应用程序?
- encryption - 即使在命令行中指定 -md5 sha256 后也会出现错误“EVP_DecryptFinal_ex:bad decrypt:crypto\evp\evp_enc.c:570”
- c# - 如何创建一个要求 1 到 100 之间的值并使用循环的 C# 程序
- angular - RxJs - 无法解析可观察的流
- javascript - 循环通过 facebook messenger bot 元素
- python - 如何更改单个 tkinter (ttk) 树视图标题的字体?