Skip to content

Commit aa01465

Browse files
committed
Fixed 72
1 parent 27a1313 commit aa01465

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/08-advanced-patterns/72-as-prop-with-forward-ref.solution.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ComponentProps,
2+
ComponentPropsWithRef,
33
ElementType,
44
ForwardedRef,
55
forwardRef,
@@ -21,15 +21,18 @@ type DistributiveOmit<T, TOmitted extends PropertyKey> = T extends any
2121
? Omit<T, TOmitted>
2222
: never;
2323

24-
function UnwrappedLink<T extends ElementType>(
24+
export const UnwrappedLink = <TAs extends ElementType>(
2525
props: {
26-
as?: T;
27-
} & DistributiveOmit<ComponentProps<ElementType extends T ? "a" : T>, "as">,
26+
as?: TAs;
27+
} & DistributiveOmit<
28+
ComponentPropsWithRef<ElementType extends TAs ? "a" : TAs>,
29+
"as"
30+
>,
2831
ref: ForwardedRef<any>,
29-
) {
32+
) => {
3033
const { as: Comp = "a", ...rest } = props;
3134
return <Comp {...rest} ref={ref}></Comp>;
32-
}
35+
};
3336

3437
const Link = fixedForwardRef(UnwrappedLink);
3538

0 commit comments

Comments
 (0)