docs: add docs for JSX middleware
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by Yusuke Wada · parent 9ae8f72 · Browse files · 2 files·+90 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+90 added−0 removed
- other:+90 added−0 removed
Provenance
- Commit
e6c916a- Tree
1b005cd- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
9ae8f72
2 files changed+90 added−0 removed
modified:src/middleware/jsx/README.md+89 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889# JSX Middleware
JSX Middleware enable rendering HTML with JSX syntax.It's just for Sever-Side-Rendering. No virtual DOM.This middleware supports only for TypeScript.
## Settings
tsconfig.json:
```json{ "compilerOptions": { "jsx": "react", "jsxFactory": "h" }}```
## Usage
index.tsx:
```tsximport { Hono } from 'hono'import { h, jsx } from 'hono/jsx'
const app = new Hono()
app.use('*', jsx())
const Layout = (props: { children?: string }) => { return ( <html> <body>{props.children}</body> </html> )}
const Top = (props: { messages: string[] }) => { return ( <Layout> <h1>Hello Hono!</h1> <ul> {props.messages.map((message) => { return <li>{message}!!</li> })} </ul> </Layout> )}
app.get('/', (c) => { const messages = ['Good Morning', 'Good Evening', 'Good Night'] return c.render(<Top messages={messages} />)})
app.fire()```
## dangerouslySetInnerHTML
```tsxapp.get('/foo', (c) => { const html = { __html: 'JSX · SSR' } return c.render(<div dangerouslySetInnerHTML={html} />)})```
## Tips for Cloudflare Workers
It's useful to use Miniflare's`live-reload` option for developing.
package.json:
```json{ "scripts": { "build": "esbuild --bundle --outdir=dist ./src/index.tsx", "dev": "miniflare --live-reload --debug" }}```
wrangler.toml:
```tomlcommand = "yarn run build"```modified:README.md+1 added
71 unmodified lines72 - [Cookie parsing / serializing](https://github.com/honojs/hono/tree/master/src/middleware/cookie/)73 - [CORS](https://github.com/honojs/hono/tree/master/src/middleware/cors/)74 - [ETag](https://github.com/honojs/hono/tree/master/src/middleware/etag/)75 - [GraphQL Server](https://github.com/honojs/hono/tree/master/src/middleware/graphql-server/)76+- [JSX](https://github.com/honojs/hono/tree/master/src/middleware/jsx/)77 - [JWT Authentication](https://github.com/honojs/hono/tree/master/src/middleware/jwt/)78 - [Logger](https://github.com/honojs/hono/tree/master/src/middleware/logger/)79 - [Mustache template engine](https://github.com/honojs/hono/tree/master/src/middleware/mustache/) (Only for Cloudflare Workers)80 - [JSON pretty printing](https://github.com/honojs/hono/tree/master/src/middleware/pretty-json/)664 unmodified lines