Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapStateToProps #238

Open
martinc360 opened this issue Jun 1, 2018 · 1 comment
Open

MapStateToProps #238

martinc360 opened this issue Jun 1, 2018 · 1 comment

Comments

@martinc360
Copy link

I have a small problem with mapStateToProps and cant find the sollutions.

The code below works, but i want to use mapStateToProps correctly as described in your videos.

If I change the line "post: posts" to "post: posts[ownProps.match.params.id]" and changed the render method from "{post[this.props.match.params.id].title}" to "{post.title}" I got the following message:

Uncaught TypeError: Cannot read property '242339' of null

Thanks in advance!

`class PostsShow extends Component {
componentDidMount() {
const { id } = this.props.match.params;
this.props.fetchPost(id);
}

render() {
const { post } = this.props;
console.log(this.props.post);

if (!post ) {
  return (<div>Loading...</div>);
}

return (
  <div>
    {post[this.props.match.params.id].title}
  </div>
);

}
}

const mapStateToProps = ({posts}, ownProps) => {
console.log(ownProps);

return {
post: posts
};
};`

@David2913
Copy link

Do you have a repo with your code? I'd like to check it out and help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants