react-redux passing props to child component props

Viewed 8724

I am trying to pass props to child component but the child is always receiving an empty. Here's the code to make it clearer.

When I pass to child component a state, it works Here's the working code:

 render() {
   return (
     <div>
       <PostList list={ this.state.posts }></PostList> 
  </div>
  );
}

But in my case, I want pass the props from the redux state

Not working code:

render() {
    return (
      <div>
          <PostList list={ this.props.posts }></PostList>
      </div>
      );
  }
}
function mapStateToProps(state) {
  return {
    posts: state.posts.all,
    postDetail: state.posts.post
  }
}

Any ideas why the PostList is getting an empty object in the second case even though this.props.posts is not actually empty in the calling component?

Thanks

2 Answers
Related