Use entities only mentioned in input data in denormalize

88 views Asked by At

I have reselect selector which gets rerendered every time any collection in redux store is changed, but I want it to change only when ids referenced in input data are changed. Is this possible with current denormalize function?

The code is:

// TODO: fix rerenders
const mediaSelector = createSelector(
  ({ media }) => media.byId,
  ({ documents }) => documents.byId,
  ({ photos }) => photos.byId,
  ({ photoSizes }) => photoSizes.byId,
  ({ files }) => files.locations.byId,
  (_, { media }) => media,
  (media, documents, photos, photoSizes, fileLocations, data) => {
    console.count('Connected Media');
    return denormalize(data, schema, {
      media,
      documents,
      photos,
      photoSizes,
      fileLocations,
    });
  },
);
const mapState = createStructuredSelector({
   media: mediaSelector,
});
const enhance = connect(mapState);
1

There are 1 answers

0
Goodmind On BEST ANSWER

Okay, I solved it with my npm package normalizr-entities

This is like lens for normalizr denormalization