This is a lightweight selector that can be used to match up something like your users
(or playlists
) slice of state (in this case an object) with your followees
(the users you follow, in this case an array of userId
s). Also works for something like photos
or posts
and your likedPosts
/Photos
array.
// fronted/reducers/selectors.js
import * as _ from 'lodash';
export const selectUsersByFollowees = (users, followees) => (
_.filter(
Object.values(users),
user => (followees.includes(user.id)),
)
);
// some sort of container
import { connect } from 'react-redux';
import {selectUsersByFollowees} from '../../reducers/selectors.js'
//...
const mapStateToProps = (state, ownProps) => ({
followers: selectUsersByFollowees(state.entities.users, session.currentUser.followees),
});
//...