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 LinkWrapper props to avoid collisions w React, Gatsby, etc links #10

Merged
merged 3 commits into from
Jun 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const LinkButton = styled.button`
${linkStyles};
`;

export function Link({ isButton, withArrow, containsIcon, LinkWrapper, children, ...props }) {
export function Link({ isButton, withArrow, containsIcon, LinkWrapper, children, ...rest }) {
const content = (
<Fragment>
<LinkInner withArrow={withArrow} containsIcon={containsIcon}>
Expand All @@ -147,12 +147,19 @@ export function Link({ isButton, withArrow, containsIcon, LinkWrapper, children,

if (LinkWrapper) {
const StyledLinkWrapper = LinkA.withComponent(LinkWrapper);
return <StyledLinkWrapper {...props}>{content}</StyledLinkWrapper>;
const linkWrapperProps = { ...rest };
delete linkWrapperProps.inverse;
delete linkWrapperProps.nochrome;
delete linkWrapperProps.secondary;
delete linkWrapperProps.tertiary;
Copy link
Member

Choose a reason for hiding this comment

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

I think a more idiomatic way to do this is:

const { inverse, nochrome, secondary, tertiary, ...linkWrapperProps } = rest;

return <StyledLinkWrapper {...linkWrapperProps}>{content}</StyledLinkWrapper>;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Love it. It's funny, I am so used to using that pattern when destructuring in function params, but it felt weird in this context. Makes sense, good eye :)

Updated!

return <StyledLinkWrapper {...linkWrapperProps}>{content}</StyledLinkWrapper>;
}

if (isButton) {
return <LinkButton {...props}>{content}</LinkButton>;
return <LinkButton {...rest}>{content}</LinkButton>;
}
return <LinkA {...props}>{content}</LinkA>;

return <LinkA {...rest}>{content}</LinkA>;
}

Link.propTypes = {
Expand Down