dom-chef is a lightweight library that enables developers to construct native browser DOM elements using JSX syntax, bypassing the need for unsafe `innerHTML` or verbose `document.createElement` calls. It acts as a JSX compiler target, transforming JSX into direct DOM API calls without introducing a virtual DOM layer, offering a performant and small-footprint alternative to larger frameworks. The current stable version is 5.1.1, with a consistent release cadence addressing features and stability. Key differentiators include its direct DOM manipulation approach, comprehensive support for SVG, event listeners, inline styles, nested elements, and functional components, all while shipping TypeScript types for a robust developer experience. It is not a full UI framework but a utility for DOM construction.
npm install dom-chefVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a dynamic DOM structure, including functional components, event listeners, inline styles, and SVG elements using `dom-chef`'s JSX transformation.
Migrate your project to ES Modules, use a bundler (like webpack or Rollup) that supports ESM, or configure Node.js with '"type": "module"' in your package.json. If using TypeScript, ensure your 'module' compiler option is set appropriately (e.g., 'esnext').
Remove any custom `JSX` declarations from your `globals.d.ts` or other declaration files, as they may now conflict with the types provided by `dom-chef`.
Avoid using the listed unsupported HTML tags directly within SVG JSX structures. If you need to embed such content, consider alternative rendering strategies or placing them outside the SVG context.
Always sanitize any user-generated or external HTML content before assigning it via `dangerouslySetInnerHTML`. Prefer creating DOM elements programmatically or using text content where possible to avoid this risk.
For TypeScript: Add `"jsx": "react", "jsxFactory": "h", "jsxFragmentFactory": "DocumentFragment"` to your `tsconfig.json` compiler options. For Babel: Configure `@babel/plugin-transform-react-jsx` with `pragma: 'h'` and `pragmaFrag: 'DocumentFragment'`.
Ensure your bundler is correctly configured to handle ESM modules and their default exports. For Webpack, this might involve ensuring correct `experiments.outputModule` or `resolve.fullySpecified` settings, or explicitly importing named exports if `h` is preferred.
If using dom-chef < v5.0.0, ensure you have a `globals.d.ts` file with appropriate JSX type definitions (e.g., `interface IntrinsicElements { [elemName: string]: any; }`). If using dom-chef >= v5.0.0, remove any custom `JSX.IntrinsicElements` declarations that might be conflicting with the package's bundled types.