Skip to content

Instantly share code, notes, and snippets.

@nicanordlc
Forked from yusukebe/suspense.tsx
Last active February 24, 2024 06:10
Show Gist options
  • Save nicanordlc/6b74ee956a17d08ae7859d8b1dfa1a7b to your computer and use it in GitHub Desktop.
Save nicanordlc/6b74ee956a17d08ae7859d8b1dfa1a7b to your computer and use it in GitHub Desktop.
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