Skip to content

Commit dd8176d

Browse files
Add ReactNode type docs (#627)
1 parent 0facfcd commit dd8176d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docs/react-types/ReactNode.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: ReactNode
3+
---
4+
5+
`ReactNode` is a type that describes what React can render.
6+
7+
## Parameters
8+
9+
`ReactNode` does not take any parameters.
10+
11+
## Usage
12+
13+
### Typing `children`
14+
15+
The most common use case for `ReactNode` is typing `children`.
16+
17+
```tsx
18+
import { ReactNode } from "react";
19+
20+
interface Props {
21+
children?: ReactNode;
22+
}
23+
24+
function Component({ children }: Props) {
25+
return children;
26+
}
27+
```
28+
29+
`<Component>` accepts anything that React can render as `children`. Here are some examples:
30+
31+
```tsx
32+
function Examples() {
33+
return (
34+
<>
35+
<Component>
36+
<div>Hello</div>
37+
</Component>
38+
<Component>Hello</Component>
39+
<Component>{123}</Component>
40+
<Component>
41+
<>Hello</>
42+
</Component>
43+
<Component>{true}</Component>
44+
<Component>{null}</Component>
45+
<Component>{undefined}</Component>
46+
<Component>{[1, 2, 3]}</Component>
47+
</>
48+
);
49+
}
50+
```

docs/react-types/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ title: React Types
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

77
- [`ComponentProps<ElementType>`](/docs/react-types/ComponentProps)
8+
- [`ReactNode`](/docs/react-types/ReactNode)

0 commit comments

Comments
 (0)