fastify-jsx
v0.1.2
Published
Fastify plugin for sending JSX as HTML responses.
Maintainers
Readme
fastify-jsx
Fastify plugin for sending JSX as HTML responses.
Install
pnpm install fastify-jsx
npm install fastify-jsx
bun add fastify-jsx
yarn add fastify-jsxCompatibility
| Plugin Version | Fastify Version |
|----------------|-----------------|
| ^0.1.x | ^5.x |
Usage
// ESM
import Fastify from 'fastify'
import fastifyJsx from 'fastify-jsx'
const fastify = Fastify({ logger: true })
fastify.register(fastifyJsx)
fastify.get('/', () => (
<div>JSX Payload</div>
))
fastify.get('/send', (request, reply) => {
reply.send(<div>JSX Payload</div>)
})// CJS
const fastify = require('fastify')({ logger: true })
fastify.register(require('fastify-jsx'))
fastify.get('/', () => (
<div>JSX Payload</div>
))
fastify.get('/send', (request, reply) => {
reply.send(<div>JSX Payload</div>)
})Options
render
Chooses the JSX rendering function from react-dom/server. Defaults to 'static'.
'static': Uses therenderToStaticMarkupfunction. Renders static HTML without React attributes.'string': Uses therenderToStringfunction. Renders HTML with React attributes for client-side hydration.
// ESM
fastify.register(fastifyJsx) // Render to static HTML
fastify.register(fastifyJsx, { render: 'string' }) // Render to HTML with hydration// CJS
fastify.register(require('fastify-jsx')) // Render to static HTML
fastify.register(require('fastify-jsx'), { render: 'string' }) // Render to HTML with hydrationLicense
Licensed under MIT.
