我尝试使用 react-hook 和 redux 进行状态管理编码,使用 axios 进行数据库请求编码,使用 Thunk 作为中间件处理异步性。我在一个组件中遇到问题,该组件执行 get 请求以检索过去的客户列表是 componentwillreceiveprop
# Action
export const actGetProductRequest = id => dispatch =>
callApi(`products/${id}`, "GET").then(res =>
dispatch({
type: types.EDIT_PRODUCT,
payload: { product: res.data }
})
);
------
import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import useForm from "./useForm";
import { actGetProductRequest } from "../../actions";
...
const { history, match } = props;
const getProduct = useSelector(state => state.itemEditing);
const dispatch = useDispatch();
const { …Run Code Online (Sandbox Code Playgroud)