Created
February 26, 2025 04:24
-
-
Save yusukebe/11eae657d7201e1187325d3948563e1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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