Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use createStructuredSelector with parametrized selectors? #599

Open
inikonorov opened this issue Feb 14, 2023 · 3 comments
Open

how to use createStructuredSelector with parametrized selectors? #599

inikonorov opened this issue Feb 14, 2023 · 3 comments

Comments

@inikonorov
Copy link

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?

@markerikson
Copy link
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

@inikonorov
Copy link
Author

thx

@aryaemami59
Copy link
Contributor

I believe this is no longer an issue in v5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants