0
我在組件通過終極版中獲取數據,像這樣:陣列this.props(由終極版提供)返回undefined
import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import * as actionCreators from './../../_actions/actionCreators';
import './Posts.css';
function mapStateToProps(state) {
return {posts: state.posts, comments: state.comments}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(actionCreators, dispatch);
}
class Posts extends Component {
render() {
return (
<div>
<h1>POSTS</h1>
{
console.log(this.props)
}
</div>
)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Posts);
此代碼工作,將推出以下JSON在控制檯:JSON output
當試圖登錄this.props
或this.props.posts
時,一切都會恢復正常。 但是,當試圖登錄this.props.posts.allposts
控制檯返回未定義。