import React, { Component } from 'react' import { connect } from 'react-redux' import { deletePost } from '../actions/postActions' class Post extends Component { handleClick = () => { this.props.deletePost(this.props.post.id); this.props.history.push('/'); } render() { const post = this.props.post ? (

{this.props.post.title}

{this.props.post.body}

) : (
Loading post...
); return (
{post}
) } } const mapStateToProps = (state, ownProps) => { let id = ownProps.match.params.post_id; return { post: state.posts.find(post => post.id === id) } } const mapDispatchToProps = (dispatch) => { return { deletePost: (id) => dispatch(deletePost(id)) } } export default connect(mapStateToProps, mapDispatchToProps)(Post)