Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snabbdom-jsx-lite

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snabbdom-jsx-lite

Write snabbdom templates in .jsx or .tsx (JSX for TypeScript)

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

snabbdom-jsx-lite

Write snabbdom templates in .tsx with Typescript or via Babel in .jsx files.

JSX is an XML-like syntax extension to JavaScript (ECMAScript).

Typescript support for JSX supports embedding, type checking, and compiling JSX directly to JavaScript.

Instead of using snabbdom's h (hyperscript function h(tag, data, children)) to define the virtual tree, with snabbdom-jsx-lite, you get an similar h function that is JSX compatible with Babel and Typescript.

Top level props can be any of the the initialized snabbdom modules such as class, attrs, props, on, style, hooks e.t.c.

JSX with Typescript

Install: yarn add snabbdom-jsx-lite

tsconfig.json

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "jsx"
  }
}

NOTE: jsxFragmentFactory compiler option is still being worked on in Typescript. See Typescript PR #35392

profile.tsx

import {jsx} from 'snabbdom-jsx-lite';

const profile = (
  <div>
    {/* `sel` is css selector shorthand, <img sel=".profile" /> is same as <img class={profile: true} /> */}
    <img sel=".profile" attrs={{src: 'avatar.png'}} />
    <h3>{[user.firstName, user.lastName].join(' ')}</h3>
  </div>
);

JSX with Babel

Install: yarn add snabbdom-jsx-lite @babel/plugin-transform-react-jsx

.babelrc

{
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "pragma": "jsx",
        "pragmaFrag": "Frag"
      }
    ]
  ]
}

profile.jsx

import {jsx} from 'snabbdom-jsx-lite';

const profile = (
  <div>
    <img sel=".profile" attrs={{src: 'avatar.png'}} />
    <h3>{[user.firstName, user.lastName].join(' ')}</h3>
  </div>
);

Example & Demo

A Clock App example is in provided in the repo that uses Functional Components and Fragments. See example/app.tsx

Demo is available at nojvek.github.io/snabbdom-jsx-lite

snabbdom-jsx-lite demo

Performance

snabbdom-jsx-lite's jsx function is as performant as snabbdom's h function. It avoids expensive string manipulation like other snabbdom-jsx libraries.

JSX examples

Third party JSX modules

These notable third party modules support an optional flattened flavor of jsx.

Keywords

FAQs

Package last updated on 15 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc