https://github.com/oscarotero/ssx
Fast and simple JSX library for server side
https://github.com/oscarotero/ssx
deno jsx
Last synced: about 1 year ago
JSON representation
Fast and simple JSX library for server side
- Host: GitHub
- URL: https://github.com/oscarotero/ssx
- Owner: oscarotero
- License: mit
- Created: 2024-07-15T22:06:31.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-27T12:21:35.000Z (about 1 year ago)
- Last Synced: 2025-04-10T23:14:04.991Z (about 1 year ago)
- Topics: deno, jsx
- Language: TypeScript
- Homepage: https://deno.land/x/ssx
- Size: 313 KB
- Stars: 26
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SSX
JSX is terrible for frontend. But it's an acceptable way to create HTML code in
server side, specially if it's supported by default by TypeScript and Deno.
Most of the current JSX libraries are designed to work in server and client
sides. They do complicated things like a virtual DOM, reactivity, hooks,
hydration, events, etc, in order to create interactive user interfaces.
SSX is a minimal JSX library designed to be used ONLY in server side and output
plain HTML code.
- Created in TypeScript, for Deno.
- Very fast. It's compatible with the
[`precompile` option](https://deno.com/blog/v1.38#fastest-jsx-transform)
available in Deno.
> 7-20x faster rendering times and a 50% reduction in Garbage Collection
> times.
- Run `deno task bench` to compare SSX with React, Hono and Preact.
- Designed to output HTML. It uses real HTML attributes (no more `className`).
- Great HTML and CSS documentation. Every element and property has a description
and even links to [MDN documentation](https://developer.mozilla.org/). Types
are generated using the data from
[VSCode Custom Data](https://github.com/microsoft/vscode-custom-data).
- It supports async components (components returning a Promise).
- Allows to insert raw HTML code easily (without patronizing you).
- You can add the `` declaration.
## Configuration
In your `deno.json` file:
```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "ssx"
},
"imports": {
"ssx/jsx-runtime": "https://deno.land/x/ssx/jsx-runtime.ts"
}
}
```
Alternatively, you can use
[JsDelivr as CDN](https://cdn.jsdelivr.net/gh/oscarotero/ssx/).
## Using NPM specifier
SSX is also
[published on NPM as `@lumeland/ssx`](https://www.npmjs.com/package/@lumeland/ssx):
```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "npm:@lumeland/ssx"
}
}
```
## Use with Node and Bun
If you want to use SSX with Node.js or Bun, see the `/node` folder for an
example setup using this package in a Node environment.
## Example:
```jsx
// Main component
function Main() {
return (
Welcome to SSX
{{ __html: "Raw HTML code" }}
);
}
// Async component
async function Header({ children }: { children: JSX.Children }) {
const res = await fetch(
`https://api.dictionaryapi.dev/api/v2/entries/en/${name}`,
);
const json = await res.json();
const def = json[0]?.meanings[0]?.definitions[0]?.definition;
return (
<>
Definition of {name}:
{def || "Definition not found"}
{children}
>
);
}
// String with the HTML code
console.log(await Main());
```
### Adding Doctype:
Any child with the shape `{ __html: string }` is treated as raw HTML and will
not be escaped. This allows you to insert the `` declaration
directly (something not possible in other JSX libraries):
```html
{{ __html: "" }}
...
;
```