Add example for action types in connected components using typeof#238
Add example for action types in connected components using typeof#238The-Spik3r wants to merge 1 commit intopiotrwitek:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new example component to the codebase, specifically addressing a gap in documentation regarding the proper typing of Redux action dispatchers in connected components using TypeScript's Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a helpful example for typing connected components using typeof with Redux action creators. The overall approach is sound. I've provided a few suggestions to improve code conciseness, testability, and adherence to common project conventions.
| ping: createAction<number>('ping/PING', (arg: number) => ({ | ||
| payload: { arg }, | ||
| })), |
There was a problem hiding this comment.
In the createAction call, the type annotation for the arg parameter is redundant. Since you've specified <number> as the generic argument to createAction, TypeScript can correctly infer that arg is of type number. Removing the explicit type annotation makes the code more concise.
| ping: createAction<number>('ping/PING', (arg: number) => ({ | |
| payload: { arg }, | |
| })), | |
| ping: createAction<number>('ping/PING', (arg) => ({ | |
| payload: { arg }, | |
| })), |
| } | ||
|
|
||
| // Define the functional component | ||
| const PingTestComponent: React.FC<Props> = ({ ping }) => { |
There was a problem hiding this comment.
To improve testability, it's a good practice to export the unconnected PingTestComponent. This allows you to import it directly into your test files and test its presentation and logic in isolation, without needing to set up a Redux provider or mock the connect HOC.
| const PingTestComponent: React.FC<Props> = ({ ping }) => { | |
| export const PingTestComponent: React.FC<Props> = ({ ping }) => { |
| export const PingTest = connect( | ||
| null, | ||
| { ping: actions.ping } | ||
| )(PingTestComponent); No newline at end of file |
Summary
This PR addresses issue #45 by fixing the existing documentation lacks an example demonstrating how to use the
typeofoperator for dispatching action types in connected components..Changes
Testing