Repository navigation
Expand file tree
/
Copy pathHelloUser.html
More file actions
119 lines (105 loc) · 3.62 KB
/
Copy pathHelloUser.html
File metadata and controls
119 lines (105 loc) · 3.62 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello User</title>
<!-- CDN | Content Delivery Network links -->
<!-- Creates React object e.g. line 17-23 -->
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<!-- Does the rendering lines 28-31 -->
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<!-- Don't use this in production: babel.js does local transformation into regular JS. lines 21-23 -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Ticker</th>
<th>Price</th>
</tr>
</thead>
<tbody id='root'></tbody>
</table>
<!--for is a reserved keyword in React / use htmlFor instead-->
<!--class is a reserved keyword in React / use className instead-->
<script type="text/babel">
ethereum.autoRefreshOnNetworkChange = false;
React.createElement(
'label', {
for: 'name-field'
}
)
/*even easier:*/
const Coin = ({name, ticker, price}) => (
<tr>
<td>{name}</td>
<td>{ticker}</td>
<td>{price}</td>
</tr>
);
/*function Coin(props) {
return ( /*put markup in paranteses as JS would otherwise add ; which will not be good here
<tr>
<td>{props.name}</td>
<td>{props.ticker}</td>
<td>{props.price}</td>
</tr>
);
}*/
/* class Coin extends React.Component { /*classes really are constructor functions so they can be replaced by foo().
/*
constructor(props) {
super(props);
} this will be done automatically by JS
render() {
return ( /*put markup in paranteses as JS would otherwise add ; which will not be good here
<tr>
<td>{this.props.name}</td>
<td>{this.props.ticker}</td>
<td>{this.props.price}</td>
</tr>
);
}
}
*/
class HelloMessage extends React.Component {
render() {
return (
<div>
<label htmlFor='name-field' className='mr-auto'>Name: </label>
<input type='text' id='name-field' />
Hello {this.props.name}
</div>
);
}
}
ReactDOM.render(
<>
<Coin name ='Bitcoin' ticker='BTC' price='$19000' />
<Coin name ='Ether' ticker='ETH' price='$600' />
</>,
document.getElementById('root')
);
React.createElement(
React.Fragment,
null,
React.createElement(HelloMessage, { name: "Zsolt" }),
React.createElement(HelloMessage, { name: "Sarah"})
);
</script>
<!--
Using the <></> doesn't create a new DOM element that would otherwise mess up HTML structure (e.g. ul)
React fragments.
Note: this page is a great way to try React but it's not suitable for production.
It slowly compiles JSX with Babel in the browser and uses a large development build of React.
Read this section for a production-ready setup with JSX:
https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project
In a larger project, you can use an integrated toolchain that includes JSX instead:
https://reactjs.org/docs/create-a-new-react-app.html
You can also use React without JSX, in which case you can remove Babel:
https://reactjs.org/docs/react-without-jsx.html
-->
</body>
</html>