Skip to content

how to use createStructuredSelector with parametrized selectors? #599

Description

@inikonorov

I have component, that is connected to redux via mapStateToProps by createStructuredSelector:

const mapStateToProps = createStructuredSelector({
  countReports: makeSelectCountReports(),
});

where makeSelectCountReports is:

export const makeSelectCountReports = () => createSelector(
  makeSelectReportDetails(),
  // other selectors
  (reportDetails, ...) => {
    ...
  },
);

where makeSelectReportDetails is:

export const makeSelectReportDetails = () => createSelector(
  [
    selectProjectProviderDomain(),
    (state, type) => type,
  ],
  (substate, type = ScaleAnswerKeys.Top2) => (
    type === ScaleAnswerKeys.Top2
      ? substate.top2Report
      : substate.top1Report
  ),
);

When I call makeSelectReportDetails via useSelector and not pass type arg, all works fine. But with mapStateToProps I have a problem - I think, that ownProps passed to selector and this breaks my flow. How can I use selector with mapStateToProps and not automatically pass ownProps to him?

Activity

  1. markerikson commented on Feb 14, 2023

    @markerikson
    Contributor

    Honestly, the best answer here is to not use connect, and instead use the React-Redux hooks API:

    https://react-redux.js.org/api/hooks

  2. inikonorov commented on Feb 14, 2023

    @inikonorov
    Author

    thx

  3. aryaemami59 commented on Mar 16, 2024

    @aryaemami59
    Member

    I believe this is no longer an issue in v5.

  4. changed the title [-]how to use createStructuredSelector with parametrized selectors?[/-] [+]how to use `createStructuredSelector` with parametrized selectors?[/+] on Mar 18, 2026
  5. aryaemami59 commented on Mar 18, 2026

    @aryaemami59
    Member

    Resolved in #626.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions