[英]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.