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

vdom-tag

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vdom-tag

A tag function to build virtual-dom

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-79.07%
Maintainers
1
Weekly downloads
 
Created
Source

vdom-tag

Es6 Tag function to create a virtual-dom tree from a template literal.

Very similar to hyperx, but has a better support for custom components and supports multiple root elements.

This package does not provide any way to render the tree, you have to combine it with a virtual dom implementation to make it useful (e.g. virtual-dom, React, ...).

npm install vdom-tag

Examples

import h from 'virtual-dom/h'
import createElement from 'virtual-dom/create-element'
import createTag from 'vdom-tag'

const html = createTag(h)

const title = 'world'

const tree = html`
  <div>
    <h1>hello ${title}!</h1>

    <h2>Connected users</h2>
    <ul>
      ${['Oh', 'My', 'God'].map(name => html`
        <li onclick=${() => console.log(name, 'clicked!')}>
          ${name}
        </li>
      `)}
    </ul>
  </div>
`

document.body.appendChild(createElement(tree))

Features

Multiple root elements
const list = html`
  <li>No</li>
  <li>need</li>
  <li>for</li>
  <li>React.Fragment</li>
  <li>!!</li>
`

const app = html`
  <div>
    ${list}
  </div>
`

document.body.appendChild(createElement(app))
Custom elements
const MyComponent = () => html`<p>hey</p>`
const tree = html`
  <div>
    <${MyComponent} />
  </div>
`
With React
import React from 'react'
import { render } from 'react-dom'
import createTag from 'vdom-tag'
const html = createTag(React.createElement)

const App = ({ name = 'React' }) => html`
  <p>Hello, ${name}!</p>
`

render(<App />, document.querySelector('#root'))

FAQs

Package last updated on 30 Apr 2018

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