Factory types for connect props
Author: obaydmirCreated Sep 11, 2018Updated Jun 9, 2026
LabelsenhancementIssueHunt
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.
IssueHunt Summary
Backers (Total: $60.00)
Submitted pull Requests
- #252 Document connect factory prop types
- #269 docs: add typed connect factory functions section
- #286 docs: add connect factory props example
Become a backer now!
Or submit a pull request to get the deposits!
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
Source: piotrwitek/react-redux-typescript-guide