Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from 'react';
- import { requestPosts } from '../actions/PostsActions';
- import PostBlock from '../components/PostBlock';
- import { connect } from 'react-redux';
- import { bindActionCreators } from 'redux';
- class PostsPage extends Component {
- componentDidMount() {
- setTimeout(() => {
- this.props.loadPosts(this.props.category);
- }, 500);
- }
- render() {
- console.log('render', this.props.posts);
- const Posts = this.props.posts.map((post) => {
- return <PostBlock key={post.slug} {...post}/>;
- });
- return (
- <div className="flex flex-wrap w-full p-4">
- {Posts.length ? Posts : 'No posts yet.'}
- </div>
- );
- }
- }
- const mapStateToProps = state => ({
- posts: state.posts
- });
- const mapActionsToProps = dispatch => bindActionCreators({
- loadPosts: requestPosts
- }, dispatch);
- export default connect(
- mapStateToProps,
- mapActionsToProps
- )(PostsPage);
Advertisement
Add Comment
Please, Sign In to add comment