-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
40 lines (34 loc) · 774 Bytes
/
app.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
import { htm, h, useState } from "./deps.js";
const html = htm.bind(h);
export const App = ({ page }) => {
/** @type {[string[], Function]} */
const [todos, setTodos] = useState([]);
const addTodo = () => {
setTodos((todos) => todos.concat(`Item ${todos.length}`));
};
return html`
<div class="app">
<${Header} name="ToDo's (${page})" />
<ul>
${
todos.map(
(todo) =>
html`
<li>${todo}</li>
`,
)
}
</ul>
<button onClick=${() => addTodo()}>Add Todo</button>
<${Footer}>footer content here<//>
</div>
`;
};
const Header = ({ name }) =>
html`
<h1>${name} List</h1>
`;
const Footer = (props) =>
html`
<footer ...${props} />
`;