Skip to content

Commit ac52822

Browse files
authored
Merge pull request #114 from josemoracard/jose3-03-render-with-functions
exercises 03-render-with-functions to 06-listening-to-events
2 parents 461d98f + e6d8ef4 commit ac52822

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+476
-223
lines changed

exercises/03-render-with-functions/README.es.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `03` Render with Functions
1+
# `03` Render with Functions
22

33
JSX permite usar funciones para renderizar HTML, ¡y eso es fantástico!
44

@@ -11,7 +11,7 @@ Por ejemplo:
1111
const PrintHello = () => {
1212
return <h1>Hello World</h1>;
1313
}
14-
//qué //dónde
14+
//qué //dónde
1515
ReactDOM.render(PrintHello(), myDiv);
1616
```
1717

@@ -21,4 +21,4 @@ ReactDOM.render(PrintHello(), myDiv);
2121

2222
## 💡 Pista:
2323

24-
+ La función `PrintHello` comienza con una letra en mayúscula porque la vamos a convertir en un [Componente React](https://reactjs.org/docs/react-component.html) en el próximo ejercicio.
24+
+ La función `PrintHello` comienza con una letra en mayúscula porque la vamos a convertir en un Componente React en el próximo ejercicio.

exercises/03-render-with-functions/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tutorial: "https://www.youtube.com/watch?v=EdpPIo_JNVc"
66

77
JSX allows using functions to render HTML, and that is awesome!
88

9-
It is a strongly recommended practice because, it lets you create templates and re-use your code
9+
It is a strongly recommended practice because it lets you create templates and re-use your code.
1010

1111
For example:
1212

@@ -15,7 +15,7 @@ For example:
1515
const PrintHello = () => {
1616
return <h1>Hello World</h1>;
1717
}
18-
//what //where
18+
//what //where
1919
ReactDOM.render(PrintHello(), myDiv);
2020
```
2121

@@ -25,4 +25,4 @@ ReactDOM.render(PrintHello(), myDiv);
2525

2626
## 💡 Hint:
2727

28-
+ The function `PrintHello` starts with a capital letter because we are going to convert it into a [React Component](https://reactjs.org/docs/react-component.html) in the next exercise.
28+
+ The function `PrintHello` starts with a capital letter because we are going to convert it into a React Component in the next exercise.

exercises/03-render-with-functions/app.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from "react"; //Main React.js library
1+
import React from "react"; // Main React.js library
22

3-
import ReactDOM from "react-dom"; //we use ReactDOM to render into the DOM
3+
import ReactDOM from "react-dom"; // We use ReactDOM to render into the DOM
44

55
// This function returns a string that will be rendered
66
export const PrintHello = () => {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react"; // Main React.js library
2+
3+
import ReactDOM from "react-dom"; // We use ReactDOM to render into the DOM
4+
5+
// This function returns a string that will be rendered
6+
export const PrintHello = () => {
7+
return <h1>I Love React</h1>;
8+
};
9+
10+
// what where
11+
ReactDOM.render(PrintHello(), document.querySelector("#myDiv"));
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# `03.1` Your first functional component
22

3-
Cuando creas funciones que devuelven HTML, JSX te dejará tratarlos como **Componentes**. Básicamente ellos se convertirán tus propias etiquetas HTML.
3+
Cuando creas funciones que devuelven HTML, JSX te dejará tratarlos como **Componentes**. Básicamente, se convertirán en tus propias etiquetas HTML personalizables.
44

55
> Creando nuestro primer componente funcional
66
77
> Una de las cosas que podemos hacer gracias a JSX es llamar funciones com si fueran etiquetas HTML, por ejemplo:
88
99
```js
10-
// si declaramos una función llamada `MyFunction`
10+
// Si declaramos una función llamada `MyFunction`
1111
const MyFunction = () => {
1212
return <h1>I Love React</h1>;
1313
}
1414

15-
// podemos llamar la función como una etiqueta HTML así
15+
// Podemos llamar la función como una etiqueta HTML así
1616
<MyFunction />
1717

18-
// en vez de hacerlo de la típica forma usando llaves
18+
// En vez de hacerlo de la típica forma usando paréntesis
1919
MyFunction();
2020
```
2121

2222
Cuando llamas a una función así, se convierte en un **Componente de React**, que es una función que genera (devuelve) HTML dinámicamente. Lo que sea que devuelva la función será reemplazado en el mismo lugar que el lugar original del `<MyFunction />`.
2323

2424
## 📝 Instrucciones:
2525

26-
1. En la línea de `app.jsx`, cambia la forma en la que se llama a la función, llama a la función como un **componente React** usando `<` y `>` como una etiqueta HTML (en lugar de paréntesis).
26+
1. En la línea de `app.jsx`, cambia la forma en la que se llama a la función, llama a la función como un **componente React** usando `<` y `>` como una etiqueta HTML (en lugar de paréntesis).

exercises/03.1-your-first-component/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ When you create functions that return HTML, JSX will let you treat them as **Com
1111
> One of the things we can do thanks to JSX is calling functions like they are an HTML tag, for example:
1212
1313
```js
14-
// if we declare a function called MyFunction
14+
// If we declare a function called MyFunction
1515
const MyFunction = () => {
1616
return <h1>I Love React</h1>;
1717
}
1818

19-
// we can call the function as an HTML tag like this:
19+
// We can call the function as an HTML tag like this:
2020
<MyFunction />
2121

22-
// instead of the typical way of using round brackets
22+
// Instead of the typical way of using round brackets
2323
MyFunction();
2424
```
2525

exercises/03.1-your-first-component/app.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const PrintHello = () => {
55
return <h1>I Love React</h1>;
66
};
77

8-
// change the syntax of the first parameter to make it <PrintHello /> instead of PrintHello()
8+
// Change the syntax of the first parameter to make it <PrintHello /> instead of PrintHello()
99
ReactDOM.render(PrintHello(), document.querySelector("#myDiv"));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
4+
export const PrintHello = () => {
5+
return <h1>I Love React</h1>;
6+
};
7+
8+
// Change the syntax of the first parameter to make it <PrintHello /> instead of PrintHello()
9+
ReactDOM.render(<PrintHello />, document.querySelector("#myDiv"));
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# `03.2` A real component
22

3-
En el ejericio anterior hemos creado nuestro primer componente llamado **PrintHello**, y hemos aprendido que podemos usar el componente como una etiqueta HTML.
3+
En el ejercicio anterior hemos creado nuestro primer componente llamado `PrintHello`, y hemos aprendido que podemos usar el componente como una etiqueta HTML.
44

55
```jsx
66
<PrintHello />
77
```
88

9-
Ahora, vamos a crear un nuevo componente (función) llamado **`<BootstrapCard />`** que generará el siguiente HTML:
9+
Ahora, vamos a crear un nuevo componente (función) llamado `<BootstrapCard />` que generará el siguiente HTML:
1010

1111
```jsx
1212
<div class="card m-5">
@@ -18,12 +18,14 @@ Ahora, vamos a crear un nuevo componente (función) llamado **`<BootstrapCard />
1818
</div>
1919
</div>
2020
```
21-
Nota: Este código HTML está basado en la [Bootstrap Card](https://getbootstrap.com/docs/4.0/components/card/).
21+
> Nota: Este código HTML está basado en la [Bootstrap Card](https://getbootstrap.com/docs/4.0/components/card/).
2222
2323
## 📝 Instrucciones:
2424

2525
1. Por favor, crea una función llamada `BootstrapCard` que devuelva el código de la card y usa la función `ReactDOM.render` para añadir `<BootstrapCard />` dentro del sitio web, dentro de `#myDiv`.
2626

27-
## 💡 Pista:
27+
## 💡 Pistas:
2828

2929
+ Si no sabes o no recuerdas cómo usar `ReactDOM.render`, puedes revisar los ejercicios anteriores.
30+
31+
+ Recuerda usar la sintaxis de React correcta `className` en vez de `class` cuando crees tu tarjeta de bootstrap.

exercises/03.2-a-real-component/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ tutorial: "https://www.youtube.com/watch?v=MGqH3dOhxL4"
44

55
# `03.2` A real component
66

7-
In the past exercise we created our first component called **`PrintHello`**, and we have learned that we can use the component like an HTML tag.
7+
In the past exercise we created our first component called `PrintHello`, and we have learned that we can use the component like an HTML tag.
88

99
```jsx
1010
<PrintHello />
1111
```
1212

13-
Now let's create another component (function) called **`<BootstrapCard />`** that outputs the following HTML:
13+
Now let's create another component (function) called `<BootstrapCard />` that outputs the following HTML:
1414

1515
```jsx
1616
<div class="card m-5">
@@ -23,12 +23,14 @@ Now let's create another component (function) called **`<BootstrapCard />`** tha
2323
</div>
2424
```
2525

26-
Note: This HTML code its based on the [Bootstrap Card](https://getbootstrap.com/docs/4.0/components/card/).
26+
> Note: This HTML code is based on the [Bootstrap Card](https://getbootstrap.com/docs/4.0/components/card/).
2727
2828
## 📝 Instructions:
2929

30-
1. Please create a function called `BootstrapCard` that returns the card code and use the `ReactDOM.render` function `<BootstrapCard />` to add it into the website inside `#myDiv`.
30+
1. Please create a function called `BootstrapCard` that returns the card code and use the `ReactDOM.render` function and `<BootstrapCard />` to add it into the website inside `#myDiv`.
3131

32-
## 💡 Hint:
32+
## 💡 Hints:
3333

3434
+ If you don't know or remember how to use `ReactDOM.render` you can review the past exercises.
35+
36+
+ Remember to use the correct React syntax `className` instead of `class` when creating your bootstrap card.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
33

4-
//create your function here
4+
// Create your function here
55

6-
//remember to use ReactDOM.render to include the component into the website
6+
// Remember to use ReactDOM.render to include the component into the website
77

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
4+
// Create your function here
5+
const BootstrapCard = () => {
6+
return (
7+
<div className="card m-5">
8+
<img alt="Card image cap" className="card-img-top" src="../../.learn/assets/Dylan.png?raw=true" />
9+
<div className="card-body">
10+
<h5 className="card-title">Bob Dylan</h5>
11+
<p className="card-text">
12+
Bob Dylan (born Robert Allen Zimmerman, May 24, 1941) is an American singer/songwriter, author, and artist who has been an
13+
influential figure in popular music and culture for more than five decades.
14+
</p>
15+
<a className="btn btn-primary" href="https://en.wikipedia.org/wiki/Bob_Dylan">
16+
Go to wikipedia
17+
</a>
18+
</div>
19+
</div>
20+
);
21+
};
22+
23+
// Remember to use ReactDOM.render to include the component into the website
24+
ReactDOM.render(<BootstrapCard />, document.getElementById("myDiv"));

exercises/03.3-component-properties/README.es.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# `03.3` Component Properties
22

3-
La `BootstrapCard` que acabas de hacer está [hard coded](https://www.youtube.com/watch?v=8AfUqg5pUQQ) para **Bob Dylan** únicamente.
3+
La `BootstrapCard` que acabas de hacer está [hard coded](https://es.wikipedia.org/wiki/Codificaci%C3%B3n_r%C3%ADgida) para **Bob Dylan** únicamente.
44

5-
Pero, ¿qué pasa si queremos reutilizar el componente `<BootstrapCard />` para **Paul Mccartney** o cualquier otra persona? ¿Cómo podriamos hacer? ¡Usa propiedades!
5+
Pero, ¿qué pasa si queremos reutilizar el componente `<BootstrapCard />` para **Paul McCartney** o cualquier otra persona? ¿Cómo podríamos hacer? ¡Usa propiedades!
66

77
## Usando propiedades en HTML
88

@@ -15,17 +15,17 @@ Cuando usas la etiqueta **anchor** (`<a>`) tienes que especificar la propiedad *
1515
<a href="http://twitter.com">Take me to twitter</a>
1616
```
1717

18-
Nota: Aquí estoy reutilizando la etiqueta de enlace (`<a>`) en dos enlaces diferentes
18+
> Nota: Aquí estoy reutilizando la etiqueta de enlace (`<a>`) en dos enlaces diferentes.
1919
20-
> Usando propiedades en React.js
20+
## Usando propiedades en React.js
2121

22-
En React.js también podemos crear nuestras propias etiquetas y usar nuestras propias propiedades inventadas. Por ejemplo, podríamos especificar la propiedad `title` de nuestra `<BootstrapCard />` de esta forma:
22+
En React.js también podemos crear nuestras propias etiquetas y usar nuestras propias propiedades inventadas. Por ejemplo, podríamos especificar la propiedad `title` de nuestra `<BootstrapCard />` de esta forma:
2323

2424
```jsx
25-
//para Paul Mccartney
26-
<BootstrapCard title="Paul Mccartney" />
25+
// Para Paul McCartney
26+
<BootstrapCard title="Paul McCartney" />
2727

28-
//para Bob Dylan
28+
// Para Bob Dylan
2929
<BootstrapCard title="Bob Dylan" />
3030
```
3131

@@ -46,24 +46,24 @@ Para trabajar con propiedades de componentes, tienes que especificar qué propie
4646
Por ejemplo:
4747

4848
```js
49-
// aquí estamos especificando que este componente recibirá la propiedad "title" y será un string.
49+
// Aquí estamos especificando que este componente recibirá la propiedad "title" y será un string.
5050
BootstrapCard.propTypes = {
5151
title: PropType.string
5252
};
5353
```
5454

5555
## 📝 Instrucciones:
5656

57-
1. Por favor, agrega/usa las propiedades `imageUrl`, `description`, `buttonUrl` y `buttonLabel` dentro de la función `BootstrapCard` y también en la etiqueta `<BootstrapCard />` (Con la información de Bob Dylan que trae por defecto). Hazlo de la misma manera en que `title` ha sido incluida en ambas.
57+
1. Por favor, agrega/usa las propiedades `imageUrl`, `description`, `buttonUrl` y `buttonLabel` dentro de la función `BootstrapCard` y también en la etiqueta `<BootstrapCard />` (Con la información de Bob Dylan que trae por defecto). Hazlo de la misma manera que en `title`, la cual ha sido incluida en ambas.
5858

5959
## 💡 Pistas:
6060

6161
+ Tienes que editar 3 partes del archivo (verifica los comentarios para ayudarte).
6262

63-
+ El primer paso es reemplazar las cosas escritas directamente por las propiedades del componente.
63+
+ El primer paso es reemplazar la información *hard coded* por las propiedades del componente.
6464

65-
+ El segundo paso es definir esas propiedades en el objeto prop-types en la línea 23, [aquí un video de cómo hacerlo](https://www.youtube.com/watch?v=oty7VGcXK44).
65+
+ El segundo paso es definir esas propiedades en el objeto prop-types en la línea 23. [Aquí un video de cómo hacerlo](https://www.youtube.com/watch?v=oty7VGcXK44).
6666

67-
+ El tercer paso será usar ReactDOM para añadir la declaración de la etiqueta `<BootstrapCard>` incluyendo las 5 propiedades y sus respectivos valores.
67+
+ El tercer paso será usar ReactDOM para añadir la declaración de la etiqueta `<BootstrapCard />` incluyendo las 5 propiedades y sus respectivos valores.
6868

6969
+ No tienes que renderizar el componente muchas veces, solo una.

exercises/03.3-component-properties/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ tutorial: "https://www.youtube.com/watch?v=79ho2T5Zy6U"
44

55
# `03.3` Component Properties
66

7-
The `BootstrapCard` you just made right now is [hard coded](https://www.youtube.com/watch?v=8AfUqg5pUQQ) for **Bob Dylan** only.
7+
The `BootstrapCard` you just made right now is [hard coded](https://en.wikipedia.org/wiki/Hard_coding) for **Bob Dylan** only.
88

9-
But, what if we also want to re-use the same `<BootstrapCard />` component for **Paul Mccartney** or any other person? What is the best way to do it? Use props!
9+
But, what if we also want to re-use the same `<BootstrapCard />` component for **Paul McCartney** or any other person? What is the best way to do it? Use props!
1010

1111
## Using properties in HTML
1212

13-
When you are coding HTML you are constantly using the `<tag>` properties to modify the tag behavior, for example:
13+
When you are coding HTML, you are constantly using the `<tag>` properties to modify the tag behavior, for example:
1414

1515
When you use the **anchor** tag (`<a>`) you have to specify the **href** property like this:
1616

@@ -19,21 +19,21 @@ When you use the **anchor** tag (`<a>`) you have to specify the **href** propert
1919
<a href="http://twitter.com">Take me to twitter</a>
2020
```
2121

22-
Note: Here I'm re-using the anchor tag (`<a>`) for two different links
22+
> Note: Here I'm re-using the anchor tag (`<a>`) for two different links.
2323
24-
> Using properties in React.js
24+
## Using properties in React.js
2525

26-
In React.js we also can create our own tags and use our own invented properties, for example we could specify the `title` property of our `<BootstrapCard />`, like this:
26+
In React.js we can also create our own tags and use our own invented properties. For example, we could specify the `title` property of our `<BootstrapCard />`, like this:
2727

2828
```jsx
29-
//for Paul Mccartney
30-
<BootstrapCard title="Paul Mccartney" />
29+
// For Paul McCartney
30+
<BootstrapCard title="Paul McCartney" />
3131

32-
//for Bob Dylan
32+
// For Bob Dylan
3333
<BootstrapCard title="Bob Dylan" />
3434
```
3535

36-
Our `component` function will receive all its properties (including title) through the first parameter that we can call `props`.
36+
Our `component` function will receive all of its properties (including title) through the first parameter that we can call `props`.
3737

3838
```jsx
3939
const BootstrapCard = (props) => {
@@ -50,24 +50,24 @@ To be able to work with component properties, you have to specify what propertie
5050
For example:
5151

5252
```jsx
53-
// here we are specifying that this component will receive the property "title" and it will be a string.
53+
// Here we are specifying that this component will receive the property "title" and it will be a string.
5454
BootstrapCard.propTypes = {
5555
title: PropType.string
5656
};
5757
```
5858

5959
## 📝 Instructions:
6060

61-
1. Please add/use the `imageUrl`, `description`, `buttonUrl` and `buttonLabel` properties inside the `BootstrapCard` function and also on the `<BootstrapCard />` tag (With Bob Dylan's information that has by default). Do it the same way `title` was already included in both.
61+
1. Please add/use the `imageUrl`, `description`, `buttonUrl` and `buttonLabel` properties inside the `BootstrapCard` function and also on the `<BootstrapCard />` tag (with Bob Dylan's information by default). Do it the same way `title` was already included in both.
6262

6363
## 💡 Hints:
6464

6565
+ You have to edit 3 parts of the file (check the comments for help).
6666

6767
+ The first step will be to replace the hardcoded stuff with properties inside the component.
6868

69-
+ The second step will be to define those properties in the prop-types object on line 23, [here is a video on how to do it](https://www.youtube.com/watch?v=oty7VGcXK44).
69+
+ The second step will be to define those properties in the prop-types object on line 23. [Here is a video on how to do it](https://www.youtube.com/watch?v=oty7VGcXK44).
7070

71-
+ The third step will be to use ReactDOM to add the `<BootstrapCard>` tag declaration including the 5 properties and their respective values.
71+
+ The third step will be to use ReactDOM to add the `<BootstrapCard />` tag declaration, including the 5 properties and their respective values.
7272

73-
+ You don't have to render the component two times, just once.
73+
+ You don't have to render the component twice, just once.

exercises/03.3-component-properties/app.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from "react-dom";
33
import PropType from "prop-types";
44

55
const BootstrapCard = props => {
6-
// 1) replace the hard-coded image, description, link, etc. With their property variable.
6+
// 1) Replace the hard-coded image, description, link, etc. With their property variable
77
return (
88
<div className="card m-5">
99
<img className="card-img-top" src="https://github.com/4GeeksAcademy/react-tutorial-exercises/blob/master/.learn/assets/Dylan.png?raw=true" alt="Card image cap" />
@@ -19,7 +19,7 @@ const BootstrapCard = props => {
1919
};
2020
BootstrapCard.propTypes = {
2121
title: PropType.string
22-
// 2) add here the new properties into the proptypes object
22+
// 2) Add here the new properties into the proptypes object
2323
};
2424

2525

0 commit comments

Comments
 (0)