我使用redux,但api通过连接钩子多次调用

  • 本文关键字:连接 调用 redux api reactjs redux
  • 更新时间 :
  • 英文 :


这是我的代码

const mapStateToProps = ({current, defaultdata, country, userorder, category, earlyaccess, stockdetail}: IRootState) => ({
uuid: current.uuid,
isAuthenticated: current.isAuthenticated,
defaultData: (pageName == 'category' || pageName == 'favorite') ? category.categorydata : defaultdata.defaultdata,
selectDataSetID: defaultdata.setdefaultdata,
selectCountryFullName: country.selectcountryfullname,
userorder: userorder.userorder,
earlyAccessAuthFlag: earlyaccess.earlyAccessAuthFlag,
earlyAccessAuthUrl: earlyaccess.earlyAccessAuthUrl,
totalStock: stockdetail.userstock
});
const mapDispatchToProps = {
checkAuthenticationConnect: checkAuthentication,
getDefaultData: getdefaultdataset,
getUserOrderData: editUserOrders,
getIDCategoryData: getcatid,
earlyAccessInfo: getearlyaccessinfo,
getUserStockData: getstock,
getAllFooterLinks:getsharelinks,
refreshCountryList: getdatasetcountry
};
export default connect(mapStateToProps, mapDispatchToProps)(App);

但是每个动作都是多次调用。有人能帮我解决如何停止多个api调用吗?

您没有正确地连接调度函数。

mapDispatchToProps函数必须返回包含你所有动作的对象。

看一下文档:https://react-redux.js.org/using-react-redux/connect-mapdispatch

const mapDispatchToProps = dispatch => {
`return {
checkAuthenticationConnect: dispatch({type: //action type}),

// must pass an object contains the type property as an argument to the dispatch function
increment: () => dispatch({ type: 'INCREMENT' }),
decrement: () => dispatch({ type: 'DECREMENT' }),
reset: () => dispatch({ type: 'RESET' })
}
}

相关内容

最新更新