Skip to content

Commit 5d60070

Browse files
authored
refactor(react-router): Link component self time improvements by removing 'delete' (#6456)
1 parent 9cda818 commit 5d60070

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

packages/react-router/src/link.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,7 @@ export function createLink<const TComp>(
593593
export const Link: LinkComponent<'a'> = React.forwardRef<Element, any>(
594594
(props, ref) => {
595595
const { _asChild, ...rest } = props
596-
const {
597-
type: _type,
598-
ref: innerRef,
599-
...linkProps
600-
} = useLinkProps(rest as any, ref)
596+
const { type: _type, ...linkProps } = useLinkProps(rest as any, ref)
601597

602598
const children =
603599
typeof rest.children === 'function'
@@ -606,20 +602,13 @@ export const Link: LinkComponent<'a'> = React.forwardRef<Element, any>(
606602
})
607603
: rest.children
608604

609-
if (_asChild === undefined) {
605+
if (!_asChild) {
610606
// the ReturnType of useLinkProps returns the correct type for a <a> element, not a general component that has a disabled prop
611607
// @ts-expect-error
612-
delete linkProps.disabled
608+
const { disabled: _, ...rest } = linkProps
609+
return React.createElement('a', rest, children)
613610
}
614-
615-
return React.createElement(
616-
_asChild ? _asChild : 'a',
617-
{
618-
...linkProps,
619-
ref: innerRef,
620-
},
621-
children,
622-
)
611+
return React.createElement(_asChild, linkProps, children)
623612
},
624613
) as any
625614

0 commit comments

Comments
 (0)