Skip to content

Instantly share code, notes, and snippets.

@YozhEzhi
Created November 8, 2017 10:50
Show Gist options
  • Select an option

  • Save YozhEzhi/74fd46b907e28604f9198ad96606d3fe to your computer and use it in GitHub Desktop.

Select an option

Save YozhEzhi/74fd46b907e28604f9198ad96606d3fe to your computer and use it in GitHub Desktop.
Reselect example with using props.
const makeGetPosts = () => createSelector(
(state, props) => props.user,
(state) => state.postsById,
(state) => state.usersById,
(state) => state.postListing,
(userId, posts, users, listing) => listing
.filter(id => posts[id].author === userId)
.map(id => {
const post = posts[id];
return {...post, user: users[post.author]}
}),
);
const mapState = () => {
const getPosts = makeGetPosts();
return (state, ownProps) => {
return {posts: getPosts(state, ownProps)};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment