-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditionalRenderFunction.js
More file actions
47 lines (36 loc) · 891 Bytes
/
Copy pathConditionalRenderFunction.js
File metadata and controls
47 lines (36 loc) · 891 Bytes
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
// if declaración dentro de la función de representación, pero antes de la returndeclaración.
import React from 'react';
import ReactDOM from 'react-dom';
class TodaysPlan extends React.Component {
render() {
let task;
if (!apocalypse) {
task = 'learn React.js'
} else {
task = 'run around'
}
return <h1>Today I am going to {task}!</h1>;
}
}
ReactDOM.render(
<TodaysPlan />,
document.getElementById('app')
);
// Example
import React from 'react';
import ReactDOM from 'react-dom';
const fiftyFifty = Math.random() < 0.5;
// New component class starts here:
class TonightsPlan extends React.Component {
render() {
if (fiftyFifty) {
return <h1>Tonight I'm going out WOOO</h1>;
} else {
return <h1>Tonight I'm going to bed WOOO</h1>;
}
}
}
ReactDOM.render(
<TonightsPlan />,
document.getElementById('app')
);