Skip to content

docs(connect): add typeof dispatched action type example#278

Open
ncthuc2004 wants to merge 2 commits into
piotrwitek:masterfrom
ncthuc2004:issuehunt-45-dispatch-typeof
Open

docs(connect): add typeof dispatched action type example#278
ncthuc2004 wants to merge 2 commits into
piotrwitek:masterfrom
ncthuc2004:issuehunt-45-dispatch-typeof

Conversation

@ncthuc2004

@ncthuc2004 ncthuc2004 commented May 16, 2026

Copy link
Copy Markdown

Summary

  • add a focused example in Typing connected component showing typeof action creator typing for dispatched props
  • demonstrate object shorthand dispatchProps with explicit DispatchProps and connected component export
  • mirror the change in both README_SOURCE.md and generated README.md

Why

Issue #45 requests guidance for the dispatched action type pattern when connecting components. This update documents the typeof actionCreator approach directly in the connect typing section.

Validation

  • documentation-only update
  • snippet follows existing guide conventions for connect and action creator usage

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 updates the documentation in README.md and README_SOURCE.md to include a new example demonstrating how to use object shorthand in the Redux connect function with TypeScript. The reviewer suggested a best practice of wrapping action creators in arrow functions within event handlers to prevent the React event object from being accidentally passed as an argument.

Comment thread README.md Outdated
type Props = OwnProps & DispatchProps;

const CounterButton: React.FC<Props> = ({ label, onIncrement }) => (
<button onClick={onIncrement}>{label}</button>

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

While countersActions.increment currently takes no arguments, it is a best practice in Redux documentation to wrap action creators in an arrow function when passing them to event handlers. This prevents the React event object from being accidentally passed as an argument if the action creator is later modified to accept parameters.

Suggested change
<button onClick={onIncrement}>{label}</button>
<button onClick={() => onIncrement()}>{label}</button>

Comment thread README_SOURCE.md Outdated
type Props = OwnProps & DispatchProps;

const CounterButton: React.FC<Props> = ({ label, onIncrement }) => (
<button onClick={onIncrement}>{label}</button>

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

While countersActions.increment currently takes no arguments, it is a best practice in Redux documentation to wrap action creators in an arrow function when passing them to event handlers. This prevents the React event object from being accidentally passed as an argument if the action creator is later modified to accept parameters.

Suggested change
<button onClick={onIncrement}>{label}</button>
<button onClick={() => onIncrement()}>{label}</button>

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.

1 participant