Skip to content

Commit 9410df5

Browse files
committed
7-1-3 고도화
1 parent 2ad1ac7 commit 9410df5

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

chapter7-1-3/src/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,34 @@ import './index.css';
55
import App from './App';
66
import * as serviceWorker from './serviceWorker';
77

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)
926

1027
const age = 21;
1128
ReactDOM.render(
1229
<Display ifTruthy={age >= 21}>
13-
<h1>들어오세요</h1>
30+
<whenTruthy>
31+
<h1>들어오세요</h1>
32+
</whenTruthy>
33+
<WhenFalsy>
34+
<h1>애들은 가!</h1>
35+
</WhenFalsy>
1436
</Display>,
1537
document.getElementById('root')
1638
);

0 commit comments

Comments
 (0)