我正在使用react-redux进行状态管理,并使用provider
传递状态存储,但我不知道为什么它在使用者部分我的提供者组件中显示为未定义
render(){
return (
<Provider store = {store} >
<ApolloProvider client = {client} >
<div className="row">
<SideBar />
<Center />
<RightSlidePanel />
</div>
</ApolloProvider>
</Provider>
)
}
}
RightSLidePanel组件
import { connect} from 'react-redux'
class RightSlidePanel extends React.Component{
constructor(){
super();
console.log("inside connect " + this.props);
}
//render method here
}
const mapStateToProps = state => {
return {
loggedInUser : state.loggedInUser
}
}
const mapDepatchToProps = dispatch =>{
return {
changeIsReduxWorking : answerTrueOrNot =>{
dispatch({
type : "CHANGE_REDUX_WORKING_STATUS",
data : answerTrueOrNot
});
}
}
}
export default connect(
mapStateToProps,
mapDepatchToProps
)(RightSlidePanel);
console.log的结果将以undefined
形式出现。
发布于 2018-06-03 04:12:43
你没有把道具传给super,因为props
在那里是未定义的。
constructor( props ){
super( props );
console.log("inside connect " + this.props);
}
https://stackoverflow.com/questions/50660550
复制相似问题