[英]How can I call a function inside of stateless functional component in reactjs
[英]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.