-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use hono/html for template string
- Loading branch information
Showing
1 changed file
with
29 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
export const Template = /*html*/ ` | ||
<html> | ||
<body> | ||
<h1>Counter</h1> | ||
<p>Current value: <span id="value"></span></p> | ||
<button id="increment">Increment</button> | ||
<button id="decrement">Decrement</button> | ||
<script> | ||
const value = document.getElementById("value"); | ||
const increment = document.getElementById("increment"); | ||
const decrement = document.getElementById("decrement"); | ||
const updateValue = async () => { | ||
const res = await fetch("/counter"); | ||
value.innerText = await res.text(); | ||
} | ||
increment.addEventListener("click", async () => { | ||
await fetch("/counter/increment", { method: "POST" }); | ||
await updateValue(); | ||
}) | ||
decrement.addEventListener("click", async () => { | ||
await fetch("/counter/decrement", { method: "POST" }); | ||
await updateValue(); | ||
}) | ||
updateValue(); | ||
</script> | ||
</body> | ||
</html> | ||
import { html } from "hono/html"; | ||
|
||
export const Template = html` | ||
<html> | ||
<body> | ||
<h1>Counter</h1> | ||
<p>Current value: <span id="value"></span></p> | ||
<button id="increment">Increment</button> | ||
<button id="decrement">Decrement</button> | ||
<script> | ||
const value = document.getElementById("value"); | ||
const increment = document.getElementById("increment"); | ||
const decrement = document.getElementById("decrement"); | ||
const updateValue = async () => { | ||
const res = await fetch("/counter"); | ||
value.innerText = await res.text(); | ||
}; | ||
increment.addEventListener("click", async () => { | ||
await fetch("/counter/increment", { method: "POST" }); | ||
await updateValue(); | ||
}); | ||
decrement.addEventListener("click", async () => { | ||
await fetch("/counter/decrement", { method: "POST" }); | ||
await updateValue(); | ||
}); | ||
updateValue(); | ||
</script> | ||
</body> | ||
</html> | ||
`.trim(); |