Skip to content

Commit

Permalink
fix: use hono/html for template string
Browse files Browse the repository at this point in the history
  • Loading branch information
sor4chi committed Dec 1, 2023
1 parent a30e884 commit 08b5e97
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions examples/proxy-counter/src/template.ts
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();

0 comments on commit 08b5e97

Please sign in to comment.