javascript - React - useEffect 覆盖具有多个数据的道具
问题描述
我在使用 useEffect 覆盖组件中的映射道具时遇到问题。这发生在更新 npm 之后,我现在不知道该怎么做。
我在一个组件中使用了多个 API 问题,并且数据被使用的最后一个函数覆盖
我不知道如何解决这个问题,为什么会这样?有线的想法是,当我反转功能时,最后一个将覆盖所有道具
情况1:
props.fetchAllClients();
props.fetchAllProducts();
返回:props.clientList = props.productList
案例二:
props.fetchAllProducts();
props.fetchAllClients();
返回:props.productList = props.clientList
useEffect(() => {
const fetchData = async () => {
props.fetchAllProducts();
props.fetchAllClients();
};
fetchData();
}, []);
const mapStateToProps = state => ({
clientList: state.Client.list,
productList: state.Product.list
})
const mapActionsToProps = {
addRepair: repairActions.create,
fetchAllClients: clientActions.fetchAll,
fetchAllProducts: productActions.fetchAll
}
export default connect(mapStateToProps, mapActionsToProps)(AddNewRepair);
编辑:
编辑2:
减速器/index.js
import { combineReducers } from "redux";
import { Product } from "./product";
import { Repair } from "./repair";
import { Client } from "./client";
export const reducers = combineReducers({
Product, Repair, Client,
})
减速器返回:
const reducers: Reducer<CombinedState<{
Product: {
list: any[];
groupedList: any[];
};
Repair: {
list: any[];
};
Client: {
list: any[];
};
}>, AnyAction>
解决方案
推荐阅读
- javascript - 如何在单击按钮时更改 CSS 类的属性?
- amazon-web-services - VPC 中的 AWS lambda 与 2 AZ 故障转移策略
- react-native - 使用视频的第一帧作为缩略图
- typescript - 获取通过另一个字段指定的泛型属性值的类型
- python - 我正在尝试使用 python 为 firefox 上的站点创建自动登录,但单击按钮时我不断收到此错误,请帮帮我
- mysql - 标准 UPDATE 查询非常慢
- tensorflow - 如何使用本地可解释模型无关的解释(石灰)进行多标签 GRU 回归
- kdb - KDB 仅获取仅存在于一张表中的行
- spring - 如何在春季启动中的 OAuth2AuthenticationProcessingFilter 末尾添加自定义安全过滤器?
- c# - 启动中的服务注入