小编vod*_*anh的帖子

useEffect 在结合 useDispatch、Redux 的 useSelector 时进入无限循环

我尝试使用 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)

reactjs react-redux react-hooks

5
推荐指数
1
解决办法
4938
查看次数

标签 统计

react-hooks ×1

react-redux ×1

reactjs ×1