簡體   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