davesnx / html_of_jsx

Render HTML with JSX

Home Page:https://davesnx.github.io/html_of_jsx/html_of_jsx/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Html_of_jsx logo Html_of_jsx logo

html_of_jsx is an implementation of JSX designed to render HTML on the server, without React or anything else. It's a minimal library that allows you to write components of HTML in a declarative way.

  • Supports most of features from JSX (uppercase components, fragments, optional attributes, punning)
  • but with a few improvements (lowercase components, no need to add annotations)
  • No React idioms (no className, no htmlFor, no onChange, etc...)
  • Type-safe, validates attributes and their types (it can be better thought)
  • Minimal
    • Html_of_jsx.render to render an element to HTML
    • Jsx.* to construct DOM Elements and DOM nodes (Jsx.text, Jsx.int, Jsx.null, Jsx.list)
  • Works with OCaml, Reason and mlx
  • Integrates very well with Htmx

Installation

opam install html_of_jsx
+ (library html_of_jsx.lib)
+ (preprocess (pps html_of_jsx.ppx))

Usage

let element = <a href="https://x.com/davesnx">
  <span> {"Click me!"} </span>
</a>

let html: string = Html_of_jsx.render(element);

Check the demo/server.re file to see a full example.

Check the Documentation to know more about the API and it's features.

Credits

This library was born from server-reason-react, extracted and simplified to work with HTML5.

About

Render HTML with JSX

https://davesnx.github.io/html_of_jsx/html_of_jsx/index.html

License:MIT License


Languages

Language:OCaml 84.2%Language:Reason 7.6%Language:Raku 5.6%Language:Makefile 1.5%Language:Perl 0.7%Language:Shell 0.4%