Skip to content

docs: add connect factory props example#286

Open
landeqiming666 wants to merge 2 commits into
piotrwitek:masterfrom
landeqiming666:codex/issuehunt-guide-91-connect-factory
Open

docs: add connect factory props example#286
landeqiming666 wants to merge 2 commits into
piotrwitek:masterfrom
landeqiming666:codex/issuehunt-guide-91-connect-factory

Conversation

@landeqiming666

@landeqiming666 landeqiming666 commented May 19, 2026

Copy link
Copy Markdown

Summary

  • add a source-backed Redux connected counter example using MapStateToPropsFactory
  • demonstrate per-instance memoization with ownProps while keeping inferred connected props type-safe
  • include the example in README_SOURCE.md and regenerate README.md

Fixes #91

IssueHunt bounty: https://oss.issuehunt.io/r/piotrwitek/react-redux-typescript-guide/issues/91

Verification

  • npm run ci-check
  • cd playground && npm run lint
  • cd playground && npm run tsc
  • cd playground && CI=true npm test -- --watchAll=false
  • git diff --check

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new example of a Redux connected component using a factory for mapStateToProps to demonstrate per-instance memoization. The changes include documentation updates in README.md and README_SOURCE.md, the implementation of the factory-based connected component in fc-counter-connected-factory.tsx, and a corresponding usage example. A review comment identifies a missing label property in the OwnProps type definition, which is required for type compatibility with the underlying FCCounter component.

Comment on lines +7 to +9
type OwnProps = {
initialCount?: number;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The OwnProps type is missing the label property, which is required by the FCCounter component. Since label is passed to the connected component in the usage example but not provided by mapStateToProps or mapDispatchToProps, it must be included in OwnProps to ensure type safety and avoid a compilation error when calling connect.

Suggested change
type OwnProps = {
initialCount?: number;
};
type OwnProps = {
label: string;
initialCount?: number;
};

@landeqiming666

Copy link
Copy Markdown
Author

Follow-up pushed in 136a34d to address the Gemini review note: the connected factory example's OwnProps now includes the required label prop, and README.md was regenerated from the source example.\n\nValidation: npm run ci-check passed, including doctoc/readme generation and the pre-push clean-worktree check.

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

Successfully merging this pull request may close these issues.

Factory types for connect props

1 participant