Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): Fix key warning in Hook component #88450

Merged
merged 3 commits into from
Apr 1, 2025

Conversation

malwilley
Copy link
Member

This was causing console errors in dev anywhere that the <Hook /> component was being used to render a getsentry component.

@malwilley malwilley requested a review from a team April 1, 2025 16:23
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 1, 2025
@@ -51,7 +53,9 @@ function Hook<H extends HookName>({name, ...props}: Props<H>) {
return;
}

this.setState({hooks: hooks.map(cb => cb(props))});
Copy link
Member

@evanpurkhiser evanpurkhiser Apr 1, 2025

Choose a reason for hiding this comment

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

is it always a component?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I figured that the point of this was to render getsentry components so I hope so. Maybe I can get the types to validate that

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay added some type checking, looks like all the current usages are indeed components.

Comment on lines 6 to 9
// Only allow hooks that return a React component
type ComponentHookName = {
[K in HookName]: Hooks[K] extends React.ComponentType<any> ? K : never;
}[HookName];
Copy link
Member

Choose a reason for hiding this comment

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

nice. this looks right

@malwilley malwilley merged commit 958a72b into master Apr 1, 2025
40 checks passed
@malwilley malwilley deleted the malwilley/fix/hook-console-error-key branch April 1, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants