Last active
September 3, 2024 05:41
-
-
Save yusukebe/a9b197f6b558461f4cfc9505ff1a7355 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 { 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