# vdom-tag

> A tag function to build virtual-dom

Latest version **0.1.1** (published 2018-04-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install vdom-tag
pnpm add vdom-tag
yarn add vdom-tag
bun add vdom-tag
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-04-30 |
| First published | 2018-04-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 46.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gabriel Vergnaud |
| Maintainers | gabrielvergnaud |

## Links

- npm: https://www.npmjs.com/package/vdom-tag
- npm.io page: https://npm.io/package/vdom-tag

## Recent versions

- 0.1.1 (latest) — 2018-04-30
- 0.1.0 — 2018-04-29

## README

# vdom-tag

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

Very similar to [hyperx](https://github.com/choojs/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

```js
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

```js
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

```js
const MyComponent = () => html`<p>hey</p>`
const tree = html`
  <div>
    <${MyComponent} />
  </div>
`
```

#### With React

```js
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'))
```

---
_Source: https://npm.io/package/vdom-tag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
