-
-
Save nicanordlc/6b74ee956a17d08ae7859d8b1dfa1a7b to your computer and use it in GitHub Desktop.
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
import { Hono } from 'hono' | |
import { jsxRenderer } from 'hono/jsx-renderer' | |
import { Suspense } from 'hono/jsx/streaming' | |
const app = new Hono() | |
const Component = async () => { | |
const res = await fetch('https://ramen-api.dev/shops/yoshimuraya') | |
await new Promise((r) => setTimeout(r, 8000)) // <-- delay here | |
const data = await res.json<{ shop: { name: string } }>() | |
return <div>{data.shop.name} 🍜</div> | |
} | |
app.get( | |
'*', | |
jsxRenderer( | |
({ children }) => { | |
return ( | |
<html> | |
<body>{children}</body> | |
</html> | |
) | |
}, | |
{ | |
stream: true | |
} | |
) | |
) | |
app.get('/', (c) => { | |
return c.render( | |
<Suspense fallback={<div>loading...</div>}> | |
<Component /> | |
</Suspense> | |
) | |
}) | |
export default app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment