0

您好,我想知道是否以及如何使用和实现不在类或功能组件内的 redux 操作。

我想实现这样的东西。

import { setPerson } from ./actions.js

export const registerPerson = (data) => {
  /* here we do whatever we need to set register a person */

   ... 
   .then((res) => {
     setPerson(res.data). <--- Here is the instance that I want to do.
   }).catch(err => console.warn(err);

}

目标是将registerPerson函数导入到 React 组件中,redux 操作将在导入的函数中触发。

4

1 回答 1

0

是的,您可以在then请求后端的方法中调用您的操作。但请确保,您应该派遣您的行动。

于 2020-04-26T18:20:40.803 回答