import React from 'react'; import ReactMarkdown from 'react-markdown'; import { connect } from 'react-redux'; import { fetchUserProfile } from '../actions'; import { Link } from 'react-router-dom'; class User extends React.Component { constructor (props) { super(props) this.state = { isLoading: true } } componentDidMount() { const { user } = this.props.match.params this.props.fetchUserProfile(user) .then(() => this.setState({isLoading: false})) } renderList() { const posts = this.props.user.currentUser.posts return posts.map(post => { return (

{post.title}

By {post.author}

Posted {post.time_published}

); }); } render () { const {user} = this.props const {isLoading} = this.state if (isLoading) { return

Loading

} else { const currentUser = user.currentUser return (

This is the page of: {currentUser.username}

Email: {currentUser.email}

Location: {currentUser.location}
About Me: {currentUser.bio}
{this.renderList()}
); } } } const mapStateToProps = (state) => { return { user: state.user, }; } export default connect( mapStateToProps, { fetchUserProfile } )(User);