File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,34 @@ import './index.css';
5
5
import App from './App' ;
6
6
import * as serviceWorker from './serviceWorker' ;
7
7
8
- const Display = ( { ifTruthy = true , children} ) => ( ifTruthy ) ? Children . only ( children ) : null ;
8
+
9
+ const findChild = ( children , child ) =>
10
+ Children . toArray ( children )
11
+ . filter ( c => {
12
+ console . log ( c . type ) ;
13
+ return c . type === child
14
+ } ) [ 0 ] ;
15
+
16
+ const whenTruthy = ( { children} ) =>
17
+ Children . only ( children ) ;
18
+
19
+ const WhenFalsy = ( { children} ) =>
20
+ Children . only ( children ) ;
21
+
22
+ const Display = ( { ifTruthy= true , children} ) =>
23
+ ( ifTruthy ) ?
24
+ findChild ( children , whenTruthy ) :
25
+ findChild ( children , WhenFalsy )
9
26
10
27
const age = 21 ;
11
28
ReactDOM . render (
12
29
< Display ifTruthy = { age >= 21 } >
13
- < h1 > 들어오세요</ h1 >
30
+ < whenTruthy >
31
+ < h1 > 들어오세요</ h1 >
32
+ </ whenTruthy >
33
+ < WhenFalsy >
34
+ < h1 > 애들은 가!</ h1 >
35
+ </ WhenFalsy >
14
36
</ Display > ,
15
37
document . getElementById ( 'root' )
16
38
) ;
You can’t perform that action at this time.
0 commit comments