2

It is always returning an empty array. It should only return ids and titles where the id of the drawsTRFormIdAndTitleSelector is === the transactionRequestFormId of the drawTRSelector

export const idAndTitleSelector = createSelector(
  drawTRSelector,
  drawsTRFormIdAndTitleSelector,
  (transactionRequests, idAndTitle) =>
    idAndTitle.filter(
      ({ id }) => id === transactionRequests.transactionRequestFormId
    )
);

drawTRSelector returns an array of objects that looks like:

[{
  id: "1",
  number: "1",
  transactionRequestFormId: "1",
}]

drawsTRFormIdAndTitleSelector returns an array of objects that looks like:

[{
  id: "1",
  title: "TR All Others",
}]
HMR
  • 37,593
  • 24
  • 91
  • 160
ghostagent151
  • 1,218
  • 2
  • 16
  • 33
  • 2
    `transactionRequests.transactionRequestFormId.includes` will return a boolean. You're comparing that boolean against `id`, so that will always return `false` unless `id` is `true` or `false`. – user2740650 Jun 25 '20 at 21:26
  • i see, i'll update my original post to show the other method ive tried – ghostagent151 Jun 25 '20 at 21:27
  • After the update, I see `drawTRSelector` will give you an array, so if `transactionRequests` is an array then `transactionRequests.transactionRequestFormId` isn't likely to have a value. Did you mean to access the first entry of it maybe? Some good old `console.log` lines will help you figure this out. – user2740650 Jun 25 '20 at 21:56
  • no, unfortunately i need to check all entries, not just the first – ghostagent151 Jun 25 '20 at 22:12
  • this is a simplified example, but each array can have multiple objects – ghostagent151 Jun 25 '20 at 22:13

1 Answers1

1

I think you want to do something like this:

const drawTRSelectorIds = createSelector(
  [drawTRSelector],
  (items) => items.map(({ id }) => id)
);
export const idAndTitleSelector = createSelector(
  drawTRSelectorIds,
  drawsTRFormIdAndTitleSelector,
  (ids, idAndTitle) =>
    idAndTitle.filter(({ id }) => ids.includes(id))
);
HMR
  • 37,593
  • 24
  • 91
  • 160