Skip to content

Commit 05f1c69

Browse files
committed
Clase platzi#4 - ¿Cómo se comunican los componentes? Props y atributos
1 parent 9b85eb6 commit 05f1c69

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

src/App.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,34 @@ import { TodoList } from './TodoList';
44
import { TodoItem } from './TodoItem';
55
import { CreateTodoButton } from './CreateTodoButton';
66
import './App.css';
7+
import React from 'react';
8+
9+
const defaultTodos = [
10+
{ text: "Cortar cebolla", completed: true },
11+
{ text: "Tomar el curso de ReactJS", completed: false },
12+
{ text: "Llorar con la llorona", completed: false },
13+
{ text: "Otra tarea pendiente", completed: false }
14+
];
715

816
function App() {
917
return (
10-
<div className="App">
11-
12-
<TodoCounter />
18+
<React.Fragment>
19+
20+
<TodoCounter completed={16} total={25} />
1321
<TodoSearch />
1422

1523
<TodoList>
16-
<TodoItem />
17-
<TodoItem />
18-
<TodoItem />
24+
{defaultTodos.map(todo => (
25+
<TodoItem
26+
key={todo.text}
27+
text={todo.text}
28+
completed={todo.completed}
29+
/>
30+
))}
1931
</TodoList>
2032

2133
<CreateTodoButton />
22-
</div>
34+
</React.Fragment>
2335
);
2436
}
2537

src/CreateTodoButton.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
function CreateTodoButton() {
22
return (
3-
<button>
4-
+
5-
</button>
3+
<button>+</button>
64
);
75
}
86

src/TodoCounter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function TodoCounter() {
1+
function TodoCounter({ total, completed }) {
22
return (
33
<h1>
4-
Completaste 3 de 5 TODOS
4+
Completaste {completed} de {total} TODOS
55
</h1>
66
);
77
}

src/TodoItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
function TodoItem() {
1+
function TodoItem(props) {
22
return (
33
<li>
44
<span>V</span>
5-
<p>Llorar con la Llorona</p>
5+
<p>{props.text}</p>
66
<span>X</span>
77
</li>
88
);

src/TodoList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function TodoList(props) {
1+
function TodoList({ children }) {
22
return (
33
<ul>
4-
{props.children}
4+
{children}
55
</ul>
66
);
77
}

0 commit comments

Comments
 (0)