【发布时间】:2020-06-30 18:08:13
【问题描述】:
我是 React-JS 和 Oboe.js 的新手。我正在尝试通过使用 Oboe 流式传输结果来加快一些 JSON 数据的加载。不幸的是,我无法在功能块中更新状态。所以我尝试调用另一个执行 stateSet 的函数。以下是我尝试过但不起作用的方法。它出错了使用搜索结果将其呈现在表中的映射函数。
var that = this;
oboe({
url: //url,
method: 'POST', // optional
body: //POST-DATA, // optional
})
.on('node', '*', function(things){
that.updateState(things);
// This callback will be called everytime a new object is
// found in the foods array.
console.log( 'Go eat some', things.id);
});
updateState = (props) => {
this.setState({search-result: props});
}
我不确定使用 oboe.js 和 React 更新状态的正确方法是什么?
是否有更好的库可用于将 JSON 数据流式传输到 React?
【问题讨论】: