-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogicRenderFunction.js
64 lines (53 loc) · 1.46 KB
/
LogicRenderFunction.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Una render()función debe tener una returndeclaración.
// Una render()función también puede ser un buen lugar para colocar cálculos simples que deben realizarse
class Random extends React.Component {
render() {
// First, some logic that must happen
// before rendering:
const n = Math.floor(Math.random() * 10 + 1);
// Next, a return statement
// using that logic:
return <h1>The number is {n}!</h1>;
}
}
// Cuidado con este error común:
class Random extends React.Component {
// This should be in the render function:
// const n = Math.floor(Math.random() * 10 + 1);
render() {
return <h1>The number is {n}!</h1>;
}
};
// Example
import React from 'react';
import ReactDOM from 'react-dom';
const friends = [
{
title: "Yummmmmmm",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-monkeyweirdo.jpg"
},
{
title: "Hey Guys! Wait Up!",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-earnestfrog.jpg"
},
{
title: "Yikes",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-alpaca.jpg"
}
];
// New component class starts here:
class Friend extends React.Component {
render(){
const friend = friends[0];
return (
<div>
<h1>{friend.title}</h1>
<img src={friend.src} />
</div>
);
}
}
ReactDOM.render(
<Friend />,
document.getElementById('app')
);