javascript - 在 redux-saga 中获取数据后如何在组件中调用渲染?
问题描述
我正在尝试从 redux saga 获取新数据,但我无法得到它。新日期不会在我的组件中刷新,但在 redux 中它们会更新。
sagas.js
function* getApiData(action) {
try {
// do api call
const data = yield call(fetchData);
yield put(receiveApiData(data));
} catch (e) {
console.log(e);
}
}
零件
render() {
const results = this.props.data;
if (results.lenght) { // I'm trying to check for storage length, but this does not work
return (
results.map((item, index) => {
<div key={index}>
<h1>
{item.dstOffset}
</h1>
<h1>
{item.rawOffset}
</h1>
<h1>
{item.timeZoneId}
</h1>
</div>} )
)
}
else {
return (
<div>loading</div>
)
}
}
}
const mapStateToProps = state => ({ data: state.data });
解决方案
推荐阅读
- c# - 为什么 WebClient 下载的 HTML 与 Chrome 的“查看源代码”页面不同?
- ruby-on-rails - 如何使用 Rails 迁移运行 rake 任务
- ios - 如何向 SCNProgram 提供自定义数据?
- python - 获取最常出现的字符串值?
- ssis - 比较相同 ssis 包的执行情况
- javascript - DataTables如何正确调用data.json
- javascript - 我有一个带有提交按钮的简单表单。如何使提交按钮和输入键提交表单?
- r - 在 R Shiny 中叠加图像
- jenkins - 根据 Jenkins 中的脚本输出或控制台输出发起电子邮件
- bash - 如何使用带有 echo 和 bc 命令的第二个管道?