userinfo 如何正确定义
来源:7-5 存储城市到 Redux
创心
2017-05-24
class Home extends React.Component {
constructor(props, context) {
super(props, context)
this.shouldComponentUpdate = PubeRederMixin.shouldComponentUpdate.bind(this)
}
render() {
return (
<div>
<HomeHeader cityName = {this.props.userinfo.cityName}/>
<Category/>
<div style = {{height: '15px'}}></div>
<Ad/>
<List cityName = {this.props.userinfo.cityName}/>
</div>
)
}
}
function mapStateToProps(state) {
return {
userinfo: state.userinfo
}
}这个 userinfo 哪里来的, 我在此页面修改 userinfo 都多导致无法正确获取 cityName
写回答
2回答
-
useinfo是存储到 redux 中的一组数据,redux 所有的数据可以使用22行的state获取,state.userinfo 就是获取了其中一个数据。userinfo如果得不到 cityName 说明 cityName 没有真正赋值进去,你可以通过教程中推荐的 chrome redux 插件来看看是不是真的有
012017-06-03 -
创心
提问者
2017-05-25
老师 , 可能我描述错了,userinfo 有三处, 我都修改为userinfos 结果就报错了, 改回来就正常, userinfo 不是自己定义的吗 ? 我怎么修改就报错
042017-06-03
相似问题