我遇到无限循环问题。我是React和Redux的新手,但也许我的方法不正确。在我的组件中,我这样调用调度函数:
const mapDispatchToProps = (dispatch) => {
return {
setUserProfileData: (profileData) => {
dispatch(setUserProfile(profileData.userById))
},
setUserPermissions:(userPermissionData)=>{
dispatch(setUserApps(userPermissionData.getUserPermissions))
},
setCurrentUserPermissions:(currentUserPermissionData)=>{
dispatch(setApplications(currentUserPermissionData.getUserApplication))
}
}
}
然后我使用回调方法调用另一个子组件:
<UserPermissions
userId={this.props.router.params.id}
setUserPermissionCallback={this.props.setUserPermissions}
setCurrentUserPermissionCallBack={this.props.setCurrentUserPermissions}/>
数据完美地存储在redux中,但是当我调用mapStateToProps
时,它会为以下内容创建无限循环:
currentUserApps:state.applications.currentUserApps
const mapStateToProps = (state) => {
return(
{
router : state.router,
currentUserApps:state.applications.currentUserApps
}
);
};
任何人都可以解释为什么会发生这种情况以及如何解决吗?