问题描述
大家好,我的应用程序中有两种用户:类型 A 和类型 B,它们可以通过单击主页上的个人资料卡片导航到他们的个人资料。 (用户名) 在他们根据自己的类型单击配置文件卡后,他们将看到 ProfileTypeA 或 ProfileTypeB 组件。 我还有一个名为 profile 的 redux state,其中包含配置文件用户的名称和类型。
const UserPage=(currentProfile)=>{
return(
currentProfile.type===1?
<ProfileA/>
:
<ProfileB/>
)}
const mapStatetoProps=state=>({
currentProfile:state.profile.currentProfile
})
export default connect(mapStatetoProps,null)(UserPage);
个人资料卡片组件:
const ProfileCard=({picUrl,profile,EnterProfile,history})=>{
const handleProfile=()=>{
EnterProfile(profile);
history.push(`/user/${profile.name}`)
}
return(
<Card onClick={handleProfile()}>
<BgImg bgUrl={picUrl} className='bgImg'></BgImg>
<NameBox className='name'>{profile.name}</NameBox>
</Card>
)}
const mapdispatchToProps=dispatch=>({
EnterProfile:profile=>dispatch(EnterProfile(profile))
})
export default withRouter(connect(null,mapdispatchToProps)(ProfileCard));
问题是我想在导航之前在 handleProfile 函数中更改“配置文件”redux 状态,但状态保持不变。 我应该如何解决这个问题? 提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)