Skip to content

Commit b41e6fb

Browse files
Change from Element to ElementType
1 parent 23e0d89 commit b41e6fb

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

docs/react-types/ComponentProps.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
---
2-
title: ComponentProps<Element>
2+
title: ComponentProps<ElementType>
33
---
44

5-
`ComponentProps<Element>` is a utility type that lets you grab all valid props of an element, or infer prop type of a component.
5+
`ComponentProps<ElementType>` constructs a type with all valid props of an element or inferred props of a component.
66

77
:::note
88

9-
Prefer `ComponentPropsWithRef<Element>` if ref is forwarded and `ComponentPropsWithoutRef<Element>` when ref is not forwarded.
9+
Prefer `ComponentPropsWithRef<ElementType>` if ref is forwarded and `ComponentPropsWithoutRef<ElementType>` when ref is not forwarded.
1010

1111
:::
1212

1313
## Parameters
1414

15-
- `T`: An element type. Examples include:
16-
- An HTML or SVG element such as `"div"`, `"h1"` or `"path"`.
15+
- `ElementType`: An element type. Examples include:
16+
- An HTML or SVG element string literal such as `"div"`, `"h1"` or `"path"`.
1717
- A component type, such as `typeof Component`.
1818

1919
## Usage
2020

21-
### Getting all valid props of an element
21+
### Get all valid props of an element
2222

23-
`ComponentProps<Element>` can be used to create a type that includes all valid `div` props.
23+
`ComponentProps<ElementType>` can be used to create a type that includes all valid `div` props.
2424

2525
```tsx
2626
interface Props extends ComponentProps<"div"> {
2727
text: string;
2828
}
2929

3030
function Component({ className, children, text, ...props }: Props) {
31-
// `Props` includes `text` in addition to all valid `div` props
31+
// `props` includes `text` in addition to all valid `div` props
3232
}
3333
```
3434

35-
### Infer prop types from a component
35+
### Infer component props type
3636

3737
In some cases, you might want to infer the type of a component's props.
3838

@@ -49,7 +49,7 @@ type MyType = ComponentProps<typeof Component>;
4949
// ^? type MyType = Props
5050
```
5151

52-
#### Inferring specific prop type
52+
#### Infer specific prop type
5353

5454
The type of a specific prop can also be inferred this way. Let's say you are using an `<Icon>` component from a component library. The component takes a `name` prop that determines what icon is shown. You need to use the type of `name` in your app, but it's not made available by the library. You could create a custom type:
5555

docs/react-types/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ title: React Types
44

55
`@types/react` makes some types available that can be very useful. Here's a list in alphabetical order with links to the detailed reference pages.
66

7-
- [`ComponentProps<T>`](/docs/react-types/ComponentProps)
7+
- [`ComponentProps<ElementType>`](/docs/react-types/ComponentProps)

0 commit comments

Comments
 (0)