https://github.com/nick-hio/fastify-jsx
Fastify plugin for sending JSX as HTML responses.
https://github.com/nick-hio/fastify-jsx
fastify fastify-plugin jsx plugin react react-dom typescript
Last synced: about 2 months ago
JSON representation
Fastify plugin for sending JSX as HTML responses.
- Host: GitHub
- URL: https://github.com/nick-hio/fastify-jsx
- Owner: nick-hio
- License: mit
- Created: 2025-12-07T23:15:50.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-01-04T21:59:04.000Z (6 months ago)
- Last Synced: 2026-05-05T00:46:09.442Z (about 2 months ago)
- Topics: fastify, fastify-plugin, jsx, plugin, react, react-dom, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/fastify-jsx
- Size: 34.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-jsx
[](https://www.npmjs.com/package/fastify-jsx)
Fastify plugin for sending JSX as HTML responses.
## Install
```bash
pnpm install fastify-jsx
npm install fastify-jsx
bun add fastify-jsx
yarn add fastify-jsx
```
### Compatibility
| Plugin Version | Fastify Version |
|----------------|-----------------|
| `^0.1.x` | `^5.x` |
## Usage
```jsx
// ESM
import Fastify from 'fastify'
import fastifyJsx from 'fastify-jsx'
const fastify = Fastify({ logger: true })
fastify.register(fastifyJsx)
fastify.get('/', () => (
JSX Payload
))
fastify.get('/send', (request, reply) => {
reply.send(JSX Payload)
})
```
```js
// CJS
const fastify = require('fastify')({ logger: true })
fastify.register(require('fastify-jsx'))
fastify.get('/', () => (
JSX Payload
))
fastify.get('/send', (request, reply) => {
reply.send(JSX Payload)
})
```
## Options
### `render`
Chooses the JSX rendering function from `react-dom/server`. Defaults to `'static'`.
- `'static'`: Uses the `renderToStaticMarkup` function. Renders static HTML without React attributes.
- `'string'`: Uses the `renderToString` function. Renders HTML with React attributes for client-side hydration.
```jsx
// ESM
fastify.register(fastifyJsx) // Render to static HTML
fastify.register(fastifyJsx, { render: 'string' }) // Render to HTML with hydration
```
```jsx
// CJS
fastify.register(require('fastify-jsx')) // Render to static HTML
fastify.register(require('fastify-jsx'), { render: 'string' }) // Render to HTML with hydration
```
## License
Licensed under [MIT](./LICENSE).