@flightdev/ui-preact
v1.1.0
Published
Preact SSR adapter for Flight Framework
Readme
@flightdev/ui-preact
Preact SSR adapter for Flight Framework. Lightweight React alternative with smaller bundle size.
Table of Contents
Installation
npm install @flightdev/ui @flightdev/ui-preactPeer dependencies:
npm install preact preact-render-to-stringQuick Start
import { defineUI } from '@flightdev/ui';
import { preact } from '@flightdev/ui-preact';
const ui = defineUI(preact());
const result = await ui.adapter.renderToString({
component: App,
props: { count: 0 },
});
console.log(result.html);SSR Options
Configure the Preact adapter with options:
import { preact } from '@flightdev/ui-preact';
const adapter = preact({
pretty: false,
});Available Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| pretty | boolean | false | Pretty print HTML output |
Hydration
Generate hydration scripts for client-side interactivity:
const result = await adapter.renderToString({
component: App,
props: { data },
});
const hydrationScript = adapter.getHydrationScript(result);
const html = `
<!DOCTYPE html>
<html>
<body>
<div id="app">${result.html}</div>
${hydrationScript}
</body>
</html>
`;Client Entry
import { hydrate, render } from 'preact';
import App from './App';
const container = document.getElementById('app');
const props = window.__FLIGHT_DATA__.props;
if (container.innerHTML.trim()) {
hydrate(<App {...props} />, container);
} else {
render(<App {...props} />, container);
}API Reference
preact(options?)
Create a Preact adapter instance.
function preact(options?: PreactAdapterOptions): PreactAdapter;PreactAdapter
| Method | Description |
|--------|-------------|
| renderToString(component, context?) | Render to HTML string |
| getHydrationScript(result) | Generate hydration script |
| getClientEntry() | Get client entry code |
Capabilities
| Capability | Supported | |------------|-----------| | Streaming | No | | Partial Hydration | No | | Islands | No | | Resumable | No | | SSG | Yes | | CSR | Yes | | Server Components | No |
License
MIT
