diff --git a/docs/react-types/ReactNode.md b/docs/react-types/ReactNode.md new file mode 100644 index 00000000..fe8954f9 --- /dev/null +++ b/docs/react-types/ReactNode.md @@ -0,0 +1,50 @@ +--- +title: ReactNode +--- + +`ReactNode` is a type that describes what React can render. + +## Parameters + +`ReactNode` does not take any parameters. + +## Usage + +### Typing `children` + +The most common use case for `ReactNode` is typing `children`. + +```tsx +import { ReactNode } from "react"; + +interface Props { + children?: ReactNode; +} + +function Component({ children }: Props) { + return children; +} +``` + +`` accepts anything that React can render as `children`. Here are some examples: + +```tsx +function Examples() { + return ( + <> + +
Hello
+
+ Hello + {123} + + <>Hello + + {true} + {null} + {undefined} + {[1, 2, 3]} + + ); +} +``` diff --git a/docs/react-types/index.md b/docs/react-types/index.md index 12171892..55e76cae 100644 --- a/docs/react-types/index.md +++ b/docs/react-types/index.md @@ -5,3 +5,4 @@ title: React Types `@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. - [`ComponentProps`](/docs/react-types/ComponentProps) +- [`ReactNode`](/docs/react-types/ReactNode)