docs(connect): add typeof dispatched action type example#278
docs(connect): add typeof dispatched action type example#278ncthuc2004 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
| type Props = OwnProps & DispatchProps; | ||
|
|
||
| const CounterButton: React.FC<Props> = ({ label, onIncrement }) => ( | ||
| <button onClick={onIncrement}>{label}</button> |
There was a problem hiding this comment.
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.
| <button onClick={onIncrement}>{label}</button> | |
| <button onClick={() => onIncrement()}>{label}</button> |
| type Props = OwnProps & DispatchProps; | ||
|
|
||
| const CounterButton: React.FC<Props> = ({ label, onIncrement }) => ( | ||
| <button onClick={onIncrement}>{label}</button> |
There was a problem hiding this comment.
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.
| <button onClick={onIncrement}>{label}</button> | |
| <button onClick={() => onIncrement()}>{label}</button> |
Summary
Typing connected componentshowingtypeofaction creator typing for dispatched propsdispatchPropswith explicitDispatchPropsand connected component exportREADME_SOURCE.mdand generatedREADME.mdWhy
Issue #45 requests guidance for the dispatched action type pattern when connecting components. This update documents the
typeof actionCreatorapproach directly in the connect typing section.Validation
connectand action creator usageIssueHunt Summary
Referenced issues
This pull request has been submitted to: