Build regular DOM elements using JSX
With dom-chef
, you can use Babel or TypeScript to transform JSX into plain old DOM elements, without using the unsafe innerHTML
or clumsy document.createElement
calls.
It supports everything you expect from JSX, including:
If something isn't supported (or doesn't work as well as it does in React) please open an issue!
Install
$ npm install dom-chef
Usage
Make sure to use a JSX transpiler (e.g. Babel, TypeScript compiler, esbuild, you only need one of them).
import {h} from 'dom-chef';
const handleClick = e => {
// <button> was clicked
};
const el = (
<div className="header">
<button className="btn-link" onClick={handleClick}>
Download
</button>
</div>
);
document.body.
…