import React from 'react'; import ReactMarkdown from 'react-markdown'; import { connect } from 'react-redux'; import { fetchPost } from '../actions'; import { Link } from 'react-router-dom'; class Post extends React.Component { constructor (props) { super(props) this.state = { isLoading: true } } componentDidMount() { const { slug } = this.props.match.params this.props.fetchPost(slug) .then(() => this.setState({isLoading: false})) } render () { const {posts} = this.props const {isLoading} = this.state if (isLoading) { return

Loading

} else { const post = posts.entities[posts.currentId] return (

{post.title}

); } } } const mapStateToProps = (state) => { return { posts: state.posts, slug: state.slug }; } export default connect( mapStateToProps, { fetchPost } )(Post);