A
A
Andrew2017-10-28 18:51:21
React
Andrew, 2017-10-28 18:51:21

What is the best way to filter data from the Redux Store in a component?

import React from 'react';
import { connect } from 'react-redux';
import Post from './Post';

const SavedPosts = props => {
  return <div>
      { props.map(post => <Post {...post}>) }
  </div>
}

const mapStateToProps = ({postReducer}, props) => {
    return {
        posts: postReducer.posts
    }
};

export default connect(mapStateToProps)(SavedPosts);

The code above is an example of a normal rendering of a list of Posts from a store, but this component does not have to render all of them, but only those filtered by the saved field or any other. The question is where is it better to filter them, inside the mapStateToProps function?, Inside the render function? Or previously already stored in the store in a separate field filtered? How will each option affect performance? Does it have something to do with reselect?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question