-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (71 loc) · 1.78 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React from 'react'
import ReactDOM from 'react-dom/client'
import "./index.css"
const name = "Leia Organa"
const user = {
firstName: "Leia",
lastName: "Organa",
email: "[email protected]"
}
// const user = null
function formatUserName(user) {
// return user.lastName + ", " + user.firstName
return `${user.lastName}, ${user.firstName}`
}
function generateUserEmailLink(user) {
return (
<a href={`mailto:${user.email}`}>
{formatUserName(user)}
</a>
)
}
function getGreeting(user) {
// if (user) {
// return <h1>Hello {generateUserEmailLink(user)}!!!!!!!!!!</h1>
// } else {
// return <h1>Hello, stranger!</h1>
// }
return <h1>Hello, {user ? generateUserEmailLink(user) : "stranger"}</h1>
}
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>
}
function App() {
return (
<div>
<Card>
<Greeting name="Luke Skywalker" />
<GreetingClass name="Leia Organa" />
</Card>
<Card>
<Greeting name="C-3PO" />
</Card>
<Card>
This is just a string
</Card>
<Card />
</div>
)
}
function Card(props) {
return (
<div className="card">
{props.children}
</div>
)
}
class GreetingClass extends React.Component {
render() {
return <h1>Hello, {this.props.name} (class)!</h1>
}
}
const elem = (
<div className="my-div">
<Greeting name="Luke Skywalker" />
<Greeting name="Leia Organa" />
<Greeting name="C-3PO" />
<img src="http://placekitten.com/480/480" alt="Kitty" />
</div>
)
const root = ReactDOM.createRoot(document.getElementById("root"))
root.render(<App />)