【发布时间】:2020-01-23 20:59:48
【问题描述】:
我正在尝试在组件中使用我的 redux 存储中的信息,我需要更好地了解接收信息的时间。我有以下带有 mapStateToProps 调用的导航组件,我希望将个人资料图片链接加载到标题中......比如 Facebook 或许多有用户登录的网站。
class Navigation extends Component {
// IF WE HAVE A USER PROFILE, DYNAMICALLY DEFINE THE LOGIN/PROFILE PICTURE
renderContent() {
switch (this.props.auth.data) {
case null:
return;
case false || "":
return (
<Button href='/auth/google'>Login</Button>
);
default:
return <img src={this.props.auth.data.googleImage} alt='Profile Image' />
}
}
// MY NAVIGATION COMPONENT WITH A {this.renderContent()} CALL
render() {
console.log(this.props.auth)
return (
<nav id="nav">
... this.renderContent() ...
</nav>
);
}
}
function mapStateToProps(state) {
return { auth: state.auth }
}
export default connect(mapStateToProps)(Navigation);
加载组件时,我收到一条错误消息,提示“无法读取未定义的属性 'googleImage'”。我知道这个动作是异步的,页面首先加载没有信息,然后浏览器接收信息,但我不知道如何克服这个问题 请帮忙。
谢谢,
【问题讨论】:
-
你好 Tyler,你什么时候设置你的
authreducer 的内容?
标签: javascript reactjs redux react-redux timing