How can I pass the second argument to a useSelector?

Viewed 28

I have a create selector that returns needs three arguments I'm not able to pass them correctly with useSelector().

const participantCourseApplications = useSelector((state) =>
  selectParticipantCourseApplicationIds(state, user.id, courseId)
);

This is my createSelector from the applicationsApiSlice

export const selectParticipantCourseApplicationIds = createSelector(
  [
    selectAllApplications,
    (state, participantId) => participantId,
    (state, courseId) => courseId,
  ],
  (applications, participantId, courseId) =>
    applications
      .filter(
        (filteredApplication) =>
          filteredApplication.participants.includes(participantId) &&
          filteredApplication.courseId === courseId
      )
      .map((mappedApplication) => mappedApplication.id)
);

1 Answers

Your second and third selector both use the second argument, none the third.

  [
    selectAllApplications,
    (state, participantId) => participantId,
    (state, _, courseId) => courseId,
  ],

this would use the third for courseId.

Related