# jsx-render

> [![travis](https://travis-ci.org/alecsgone/jsx-render.svg?branch=master)](https://travis-ci.org/alecsgone/jsx-render)

Latest version **1.1.1** (published 2018-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsx-render
pnpm add jsx-render
yarn add jsx-render
bun add jsx-render
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-10-09 |
| First published | 2018-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Aleks |
| Maintainers | alexrqs |
| Keywords | JSX, jsx-render, SVG-JSX |

## Links

- npm: https://www.npmjs.com/package/jsx-render
- Repository: https://github.com/alecsgone/jsx-render
- Homepage: https://github.com/alecsgone/jsx-render#readme
- Issues: https://github.com/alecsgone/jsx-render/issues
- npm.io page: https://npm.io/package/jsx-render

## Recent versions

- 1.1.1 (latest) — 2018-10-09
- 1.3.1 (next) — 2019-07-04
- 1.2.0 — 2019-06-30
- 1.1.2 — 2019-02-13
- 2.0.1 — 2018-12-30
- 2.0.0 — 2018-12-30
- 2.0.0-alpha.1 — 2018-12-30
- 2.0.0-alpha.0 — 2018-12-28
- 1.1.0 — 2018-10-08
- 1.0.0 — 2018-10-06
- 0.6.6 — 2018-05-30
- 0.6.5 — 2018-05-27
- 0.6.3 — 2018-05-21
- 0.6.2 — 2018-04-20
- 0.6.1 — 2018-04-20
- … 7 more at https://npm.io/package/jsx-render/versions

## README

## JSX-render

[![travis](https://travis-ci.org/alecsgone/jsx-render.svg?branch=master)](https://travis-ci.org/alecsgone/jsx-render)

Small file to render jsx as a stateless component from react but without the heavy kb use of it.

## Contents

- [Features](#features)
- [How To Install](#how-to-install)
- [Recipes](#recipes)

## Features

- **new** Class suport with default target: the `render()` method
- Render Basic Single Components `<div />`
- Conditional Component `{condition ? <foo/> : <bar/>}`
- Component with Data Attributes `<div data-some="attr">`
- Component with Attributes `<img src="foo.jpg">`
- Nested Component ul>li>a
- Siblings Components ul>li\*3
- Components with classname p.chan
- Map components & numbers `array.map(item => <div>{item}</div>)`
- [Fragments](#fragments)
- [Portals](#portals)
- SVG
- Component Props `<Custom foo="foo">`
- Component Children `<Custom>children</Custom>`
- Component render xlinkHref for SVG sprites
- [dangerouslySetInnerHTML](#dangerouslysetinnerhtml)
- Components withState `Redux` not included

## Fragments

```jsx
import dom, { Fragments } from 'jsx-render'

// Return siblings without direct parent component
const Foo = () => (
  <Fragments>
    <li />
    <li />
  </Fragments>
)
const ul = document.createElement('ul')
ul.appendChild(<Foo />)
```

## Portals

```jsx
import dom, { portalCreator } from 'jsx-render'

// can render the component on a diferent node than the parentNode
// useful for modals, and if the argument is not a node
// it will render as body direct son by default
function Component(node) {
  const Portal = portalCreator(node)

  return (
    <div>
      <Portal>
        <span>uno</span>
      </Portal>
    </div>
  )
}
```

## dangerouslySetInnerHTML

```jsx
function render() {
  return <div dangerouslySetInnerHTML={{ __html: '<span>StrangerDanger</span>' }} />
}
```

### How To Install

The required packages are `@babel/plugin-syntax-jsx`, `@babel/plugin-transform-react-jsx` and of course `jsx-render`, additionally you will need babel-cli, webpack or any other way to transpile the code that you prefer.

```sh
$ npm install jsx-render @babel/plugin-syntax-jsx @babel/plugin-transform-react-jsx
```

### Getting started

Make sure you have the pragma fn defined and its name is "dom"

```json
// .babelrc
{
  "presets": ["@babel/preset-env"],
  "plugins": [
    "@babel/plugin-syntax-jsx",
    ["@babel/plugin-transform-react-jsx", { "pragma": "dom" }]
  ]
}
```

Now you can create components e.g.

```jsx
import dom from 'jsx-render'

const DummyComponent = props => <div>{props.children}</div>
export default DummyComponent
```

or Fragments

```jsx
import dom, { Fragment } from 'jsx-render'
import DummyComponent from './DummyComponent'

const Modal = props => (
  <div>
    <header>Include {props.title}</header>
    <Fragment>
      <div>Body</div>
      <DummyComponent>Copyright</DummyComponent>
    </Fragment>
  </div>
)
```

## Recipes

- [Redux](recipes/redux.md)
- [ClassComponents](recipes/classComponents.md)
- [Events](recipes/events.md)

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