Skip to content

Commit ad19417

Browse files
committed
Made required context a touch harder
1 parent 2486a68 commit ad19417

3 files changed

Lines changed: 3 additions & 11 deletions

File tree

src/07-advanced-patterns/51-required-context.problem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const createRequiredContext = () => {
1414
return contextValue;
1515
};
1616

17-
return [useContext, context.Provider] as const;
17+
return [useContext, context.Provider];
1818
};
1919

2020
const [useUser, UserProvider] = createRequiredContext<{

src/07-advanced-patterns/55-as-prop.solution.2.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export const Component = <TAs extends keyof JSX.IntrinsicElements>(
55
) => {
66
const Comp = props.as as string;
77

8-
// In this version, we can remove the 'as any' because
9-
// TypeScript is able to keep up with the inference
10-
return <Comp {...props}></Comp>;
8+
return <Comp {...(props as any)}></Comp>;
119
};
1210

1311
const example1 = <Component as="a" href="awdawd"></Component>;

src/07-advanced-patterns/56-as-prop-with-custom-components.solution.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ export const Component = <
88
} & ComponentProps<T>,
99
) => {
1010
const Comp = props.as;
11-
return (
12-
<Comp
13-
// The 'as any' is still needed, because 'as' is SO generic
14-
// that TypeScript can't handle it.
15-
{...props}
16-
></Comp>
17-
);
11+
return <Comp {...props}></Comp>;
1812
};
1913

2014
const Link = (props: { href: string; children?: React.ReactNode }) => {

0 commit comments

Comments
 (0)