reactjs - 如何使用来自 api 的 redux 获取数据?
问题描述
嗨,我的朋友们,我将使用 redux 从 api 获取数据 如果您需要更改代码,我的代码可以在下面的链接中找到
这是我的项目链接:
https://codesandbox.io/s/getdatafromapiwhithaxiosusingreduxinreactproject-s8ckq
我收到了来自 api 的数据,但如何在组件中使用它?
解决方案
您尚未创建Reducer.js
文件
您需要创建该文件,并在其中包含一个减速器。
使用导出减速器export default reducer;
将数据放入您的 props 对象后,例如products
,您需要像这样映射它:
class App extends Component {
render() {
return {
this.props.products.map((product, i) => (
<li>product.title</li>
))
}
}
}
推荐阅读
- javascript - 从输入中绘制多个画布并计算如何对齐它们
- jenkins - Jenkins 不运行 PM2
- java - 使用 Apache Commons Net 发送到 FTP 后文件大小增加
- android - 更好的 gradle 表达式为所有子项目执行 fileTrees.add()
- sql - SQL,foreach-loop-like INSERT 基于需要重新选择的插入值,可能吗?
- unity3d - 如何在 Unity VR 中正确缩放导入的 3D 模型?
- ionic-framework - 运行时错误语法错误:位置 0 处的 JSON 中的意外标记 <
- excel - 如何在 Excel(和 Google 表格)中找到稀疏数组的宽度和宽度?
- python - 将值设置为 CellVariable
- xml - kotlin 从 imageview 获取图像名称