Snabbdom-jsx is a lightweight library (v0.4.2, latest stable) that enables writing Snabbdom virtual DOM nodes using JSX syntax with Babel. It transforms JSX attributes into Snabbdom's data format, supporting namespaces like on- for events, class- for classes, and style- for styles. Unlike full frameworks, it stays focused on the virtual DOM layer, allowing flexible architecture choices. Released irregularly with minor updates since 2016, it ships TypeScript types and avoids React's component class overhead by using simple functions. Key differentiator: direct mapping of JSX to Snabbdom's modular system without additional abstractions.
npm install snabbdom-jsxVerified import paths — ran on the pinned version, not inferred.
Shows how to set up the JSX pragma, import html, initialize snabbdom with modules, create a virtual node with event listener, and patch the DOM.
Use 'key' as a direct attribute on the element, e.g., <div key="myId">.
Use prefix notation: on-click for events, class-visible for classes.
Specify 'key' directly on the component element.
Upgrade to v0.3.1+ and ensure child arrays are flattened.
Update component definitions to accept { attrs, children } object or (attributes, children) parameters.Run 'npm install snabbdom-jsx' and ensure it's listed in package.json dependencies.
Change import to: import { html } from 'snabbdom-jsx'.Ensure the first line of the file is '/** @jsx html */' (or the correct pragma function).
Use <div key="myKey">...</div> directly, not <div props={{key: 'myKey'}}>.</div>.