Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created February 26, 2025 04:24
Show Gist options
  • Save yusukebe/11eae657d7201e1187325d3948563e1c to your computer and use it in GitHub Desktop.
Save yusukebe/11eae657d7201e1187325d3948563e1c to your computer and use it in GitHub Desktop.
import { createRoute } from 'honox/factory'
import { Suspense } from 'hono/jsx'
import { getContext } from 'hono/context-storage'
export const getData = async (userId: string | undefined) => {
await new Promise((resolve) => setTimeout(resolve, 1000))
if (!userId) {
return undefined
}
const userData = getContext().var.db.getUser(userId)
return userData
}
async function UserComponent({ userId }) {
const user = await getData(userId)
if (!user) {
getContext().status(404)
return <div>User not found</div>
}
return <div>User name is {user.name}</div>
}
export default createRoute(async (c) => {
const userId = c.req.query('userId')
return c.render(
<Suspense fallback={<div>Loading...</div>}>
<UserComponent userId={userId} />
</Suspense>
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment