Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Last active September 3, 2024 05:41
Show Gist options
  • Save yusukebe/a9b197f6b558461f4cfc9505ff1a7355 to your computer and use it in GitHub Desktop.
Save yusukebe/a9b197f6b558461f4cfc9505ff1a7355 to your computer and use it in GitHub Desktop.
import { Hono } from 'hono'
import { Suspense } from 'hono/jsx'
import { jsxRenderer } from 'hono/jsx-renderer'
const app = new Hono()
app.get(
'*',
jsxRenderer(
({ children }) => {
return (
<html>
<body>{children}</body>
</html>
)
},
{ stream: true }
),
async (c, next) => {
await next()
c.header('Content-Encoding', 'Identity')
}
)
let count = 0
const CounterComponent = async ({ message }: { message: string }) => {
await new Promise((r) => setTimeout(r, 200))
if (count++ > 10) {
count = 0
return <div>Done!</div>
}
return (
<Suspense fallback={message}>
<CounterComponent message={count.toString()} />
</Suspense>
)
}
app.get('/', (c) => {
return c.render(<CounterComponent message="Start!" />)
})
export default app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment