Skip to content

Add example for action types in connected components using typeof#238

Open
The-Spik3r wants to merge 1 commit intopiotrwitek:masterfrom
The-Spik3r:fix-issue-1773946640890
Open

Add example for action types in connected components using typeof#238
The-Spik3r wants to merge 1 commit intopiotrwitek:masterfrom
The-Spik3r:fix-issue-1773946640890

Conversation

@The-Spik3r
Copy link
Copy Markdown

Summary

This PR addresses issue #45 by fixing the existing documentation lacks an example demonstrating how to use the typeof operator for dispatching action types in connected components..

Changes

  • Improved type definitions and implementation
  • Added proper generic type handling
  • Enhanced code maintainability

Testing

  • Code follows project style guidelines
  • Tests pass locally
  • Ready for review

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 typeof operator. This addition aims to clarify best practices for developers, improving type safety and maintainability when integrating Redux with React components.

Highlights

  • Documentation Enhancement: Added a new example demonstrating the use of typeof for dispatching action types in Redux connected components, directly addressing issue suggestion: add info about dispatched action types #45.
  • Type Definitions: Implemented improved type definitions and proper generic type handling within the new example component.
  • Code Maintainability: Enhanced code maintainability through clearer type usage for Redux action dispatching in connected components.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

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

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 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.

Comment on lines +8 to +10
ping: createAction<number>('ping/PING', (arg: number) => ({
payload: { arg },
})),
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

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.

Suggested change
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 }) => {
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

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.

Suggested change
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
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 file is missing a final newline character. Most files in this project end with a newline, so for consistency, one should be added here. This is a common convention that can prevent issues with some tools and file concatenations.

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