title: how to get posts by id in redux selector
body: <p>I'm trying to retrieve all posts by according to userId. I'm unsure how to get the logic to work, where its resuable through out the whole application.</p>
  
  <p>I want be able to call the selector <code>getUserPosts</code> , and be able to iterated it on user profile page, how would i do this ?</p>
  
  <p>this is what i have  </p>
  
  <p><strong>selectors</strong></p>
  
  <pre><code>export const getPosts = () =&gt; // this gets all posts
      createSelector(
          postSelector,
          (state) =&gt; state.posts,
      );
  export const getUserPosts = () =&gt;  // how i do i get all posts based on user id i pass state here 
      createSelector(
          postSelector,
          (state) =&gt; state.posts.filter((user) =&gt; user.userId === state.id)
      )
  </code></pre>
  
  <p><strong>container</strong></p>
  
  <pre><code>import { connect } from "react-redux";
  import { createStructuredSelector } from "reselect";
  import Profile from "./../components/Profile/Profile"
  import { getUserPosts } from "./../selectors/selectors";
  const mapStateToProps = createStructuredSelector({
      userPosts: getUserPosts()
  });
  
  export default connect(
      mapStateToProps,
      null,
  )(Profile);
  </code></pre>
  
  <p><strong>reducer</strong></p>
  
  <pre><code>import produce from "immer";
  import * as types from "../actionTypes/postActionTypes";
  import { validation } from '../utils';
  export interface postState {
    posts: any[];
    postPage: any;
    error: any;
    titleError: any;
    bodyError: any;
    title: string
    postContent: string
  
  }
  
  const initialState: postState = {
    posts: [],
    postPage: {},
    titleError: null,
    bodyError: null,
    title: "",
    postContent: "",
    error: null
  };
  
  const postReducer = (state = initialState, action: any): postState =&gt;
    produce(state, (draft) =&gt; {
      switch (action.type) {
        case types.GET_POSTS_SUCCESS:
          draft.posts = action.payload;
          return;
      }
    });
  
  export default postReducer;
  </code></pre>