-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
67 lines (56 loc) · 1.75 KB
/
example.html
File metadata and controls
67 lines (56 loc) · 1.75 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script src="./jsx.js"></script>
<title>jsx</title>
</head>
<body>
<div id="root"></div>
<script>
const List = ({ list, children }) => {
return list.map(n => jsx`<li style=${{ color: "red" }}>${n}</li>`)
}
const Ul = jsx`<ul>
<li>0</li>
<${List} list=${[1, 2, 3]}>
<div>test</div>
</${List}>
<li>4</li>
<li>
<code ref=${c => console.log("code", c.innerHTML)}>test</code>
</li>
</ul>`
document.getElementById("root").append(Ul)
const ref = {}
const button = jsx`<button className="test" ref=${ref} onClick=${() =>
console.log(ref)}>console ref</button>`
document.getElementById("root").append(button)
const paras = jsx`
<${jsx.frag}>
<p>1</p>
<p>2</p>
<p>3</p>
</${jsx.frag}>`
document.getElementById("root").append(paras)
const timeout = (delay = 1000) =>
new Promise(resolve => setTimeout(resolve, delay))
const fetchData = async value => {
await timeout()
return value
}
const App = async ({ value }) => {
const data = await fetchData(value)
return jsx`<h1>${data}</h1>`
}
const Index = jsx`
<${jsx.Suspense} fallback=${jsx`<p>loading...</p>`}>
<${App} value=${"qwq"}/>
</${jsx.Suspense}>`
document.getElementById("root").append(Index)
document.getElementById("root").append(jsx`<footer>---<footer>`)
</script>
</body>
</html>