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

Factory types for connect props #91

Open
obaydmir opened this issue Sep 11, 2018 · 2 comments
Open

Factory types for connect props #91

obaydmir opened this issue Sep 11, 2018 · 2 comments

Comments

@obaydmir
Copy link

obaydmir commented Sep 11, 2018

In advanced scenarios where you need more control over the rendering performance, mapDispatchToProps() can also return a function. In this case, that function will be used as mapDispatchToProps() for a particular component instance. This allows you to do per-instance memoization. You can refer to issue.

Example:

const mapStateToPropsFactory: MapStateToPropsFactory<StateProps, OwnProps, State> = () => {
  // Example selector
  const mySelector = makeMySelector();

  return (state, ownProps) => {
    return mySelector(state, ownProps);
  }
}

export default connect(mapStateToPropsFactory)(MyComponent);

In case you return any or other type, you will get an error which can confuse you. When you don't define the return type of this function, it will work, but I rather want to be strict.

@IssueHuntBot
Copy link

@BoostIO funded this issue with $15. Visit this issue on Issuehunt

@IssueHuntBot
Copy link

@IssueHunt has funded $45.00 to this issue.


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

No branches or pull requests

3 participants