Skip to content

Commit

Permalink
ComponentProps
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed May 2, 2024
1 parent 3879612 commit 6a34621
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion exercises/06.styling/02.problem.component/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ case), you'll want to borrow the type definition for that element from React.
Here's how you do that (for a `span` element rather than `div`):

```tsx
function MySpan(props: React.HTMLAttributes<HTMLSpanElement>) {
function MySpan(props: React.ComponentProps<'span'>) {
return <span {...props} />
}
```
Expand Down
2 changes: 1 addition & 1 deletion exercises/06.styling/02.problem.component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createRoot } from 'react-dom/client'
// 🐨 Also automatically add the fontStyle: 'italic' style to the style prop so consumers don't have to provide that
// 🐨 And automatically add the "box" className to the className prop so consumers don't have to provide that as well.

// 💯 as a bonus, have this accept any number of additional props (typed as React.HTMLAttributes<HTMLDivElement>)
// 💯 as a bonus, have this accept any number of additional props (typed as React.ComponentProps<'div'>)
// and apply those to the rendered div as well.

// 🐨 update all of these to use the <Box> component with the appropriate props.
Expand Down
2 changes: 1 addition & 1 deletion exercises/06.styling/02.solution.component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Box({
style = {},
className = '',
...otherProps
}: React.HTMLAttributes<HTMLDivElement>) {
}: React.ComponentProps<'div'>) {
return (
<div
className={`box ${className}`}
Expand Down
2 changes: 1 addition & 1 deletion exercises/06.styling/03.problem.size-prop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Box({
// 🐨 add a size prop here
...otherProps // 🦺 union this with an object that has a size prop type here which is
// optional and one of "small", "medium", or "large"
}: React.HTMLAttributes<HTMLDivElement>) {
}: React.ComponentProps<'div'>) {
// 🐨 based on the size prop, define a new variable called sizeClassName
return (
<div
Expand Down
2 changes: 1 addition & 1 deletion exercises/06.styling/03.solution.size-prop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Box({
...otherProps
}: {
size?: 'small' | 'medium' | 'large'
} & React.HTMLAttributes<HTMLDivElement>) {
} & React.ComponentProps<'div'>) {
const sizeClassName = size ? `box--${size}` : ''
return (
<div
Expand Down

0 comments on commit 6a34621

Please sign in to comment.