繁体   English   中英

我们可以在不是功能组件的 function 中使用 redux 操作,也可以在 Z6F26340DBB728849B1903 中使用 class 组件

[英]Can we use redux actions inside a function that is not a functional component or a class component in reactJS

您好,我想知道是否以及如何使用和实现不在 class 或功能组件内的 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 function 导入到 React 组件中,其中 redux 操作将在导入的 function 中触发。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM