forked from kay-is/react-from-zero
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path08-nested-components.html
More file actions
44 lines (34 loc) · 1.13 KB
/
08-nested-components.html
File metadata and controls
44 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!doctype html>
<title>08 Componentes Aninhados - React do Zero</title>
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<div id="app"></div>
<script type="text/babel">
// Componentes, como elementos, podem ser aninhados
// para isso, a propriedade filho é usada dentro do componente
// Esse componente apenas envelopa seus filhos em um elemento <li>
function Item(props) {
return <li>{props.children}</li>
}
// Esse componente envelopa seus filhos em um elemento <ul>
function List(props) {
return <ul>{props.children}</ul>
}
// Se a <List> for criada sem filhos ela recee um filho default
List.defaultProps = {
children: <Item>Empty</Item>
}
// Agora renderizamos duas <List>, com e sem Itens
var reactElement =
<div>
<List/>
<List>
<Item>First</Item>
<Item>Second</Item>
<Item>Third</Item>
</List>
</div>
var renderTarget = document.getElementById("app")
ReactDOM.render(reactElement, renderTarget)
</script>