必要な場所だけブラウザで強化する
import { useState } from 'hono/jsx'
export function LikeButton({ action, liked: initial, count: initialCount }) {
const [liked, setLiked] = useState(initial)
const [count, setCount] = useState(initialCount)
async function toggle() {
const next = !liked
setLiked(next)
setCount((value) => value + (next ? 1 : -1))
await fetch(action, { method: 'POST' })
}
return <button onClick={toggle}>♥ {count}</button>
}