unxp

Untitled

Mar 28th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import { requestPosts } from '../actions/PostsActions';
  3. import PostBlock from '../components/PostBlock';
  4. import { connect } from 'react-redux';
  5. import { bindActionCreators } from 'redux';
  6.  
  7. class PostsPage extends Component {
  8.   componentDidMount() {
  9.     setTimeout(() => {
  10.       this.props.loadPosts(this.props.category);
  11.     }, 500);
  12.   }
  13.  
  14.   render() {
  15.     console.log('render', this.props.posts);
  16.     const Posts = this.props.posts.map((post) => {
  17.         return <PostBlock key={post.slug} {...post}/>;
  18.       });
  19.  
  20.     return (
  21.       <div className="flex flex-wrap w-full p-4">
  22.         {Posts.length ? Posts : 'No posts yet.'}
  23.       </div>
  24.     );
  25.   }
  26. }
  27.  
  28.  
  29. const mapStateToProps = state => ({
  30.   posts: state.posts
  31. });
  32.  
  33. const mapActionsToProps = dispatch => bindActionCreators({
  34.     loadPosts: requestPosts
  35. }, dispatch);
  36.  
  37. export default connect(
  38.   mapStateToProps,
  39.   mapActionsToProps
  40. )(PostsPage);
Advertisement
Add Comment
Please, Sign In to add comment