File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 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+ ``` 
Original file line number Diff line number Diff 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 ) 
                                 You can’t perform that action at this time. 
               
                  
0 commit comments