# jsonml-to-react-element

> To convert JsonML to React element.

Latest version **1.1.11** (published 2018-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonml-to-react-element
pnpm add jsonml-to-react-element
yarn add jsonml-to-react-element
bun add jsonml-to-react-element
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.11 |
| Published | 2018-05-07 |
| First published | 2017-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Benjy Cui |
| Maintainers | benjycui |
| Keywords | jsonml, react, element, markdown |

## Links

- npm: https://www.npmjs.com/package/jsonml-to-react-element
- Repository: https://github.com/benjycui/jsonml-to-react-element
- Homepage: https://github.com/benjycui/jsonml-to-react-element#readme
- Issues: https://github.com/benjycui/jsonml-to-react-element/issues
- npm.io page: https://npm.io/package/jsonml-to-react-element

## Dependencies (1)

- [jsonml.js](https://npm.io/package/jsonml.js.md) ^0.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.11 (latest) — 2018-05-07
- 1.1.10 — 2018-04-27
- 1.1.9 — 2018-04-27
- 1.1.8 — 2018-04-26
- 1.1.7 — 2018-04-26
- 1.1.3 — 2018-04-22
- 1.1.2 — 2018-04-19
- 1.1.1 — 2018-04-14
- 1.1.0 — 2018-03-06
- 1.0.0 — 2017-01-17

## README

# jsonml-to-react-element

[![](https://img.shields.io/travis/benjycui/jsonml-to-react-element.svg?style=flat-square)](https://travis-ci.org/benjycui/jsonml-to-react-element)
[![npm package](https://img.shields.io/npm/v/jsonml-to-react-element.svg?style=flat-square)](https://www.npmjs.org/package/jsonml-to-react-element)
[![NPM downloads](http://img.shields.io/npm/dm/jsonml-to-react-element.svg?style=flat-square)](https://npmjs.org/package/jsonml-to-react-element)
[![Dependency Status](https://david-dm.org/benjycui/jsonml-to-react-element.svg?style=flat-square)](https://david-dm.org/benjycui/jsonml-to-react-element)

To convert JsonML to React Component.

## Installation

```bash
npm install --save jsonml-to-react-element
```

## Usage

Basic:

```js
const ReactDOM = require('react-dom');
const toReactElement = require('jsonml-to-react-element');

const title = [
  'h1',
  'Hello world!',
];

ReactDOM.render(toReactElement(title), document.getElementById('content'));
```

With converters:

```js
const React = require('react');
const ReactDOM = require('react-dom');
const toReactElement = require('jsonml-to-react-element');

const website = [
  'section',
  [
    'header',
    ...
  ],
  [
    'article',
    [
      'h1',
      'Hello world!',
    ],
  ],
  [
    'footer',
    ...
  ]
];

const html5to4 = [
  [
    (node) => ['section', 'header', 'article', 'footer'].indexOf(node[0]) > -1,
    (node, index) => React.createElement(
      'div',
      { key: index },
      node.slice(1).map((child) => toReactElement(child, html5to4))
    )
  ],
  ...
];

ReactDOM.render(
  toReactElement(website, html5to4),
  document.getElementById('content')
);
```

## API

### toReactElement(jsonml: Object [, converters: Array]): React.Component

To convert JsonML to React Component with converters.

#### converters: Array[Pair[Function, Function]]

Converters which are passed to `toReactElement` will concat with [default converters](https://github.com/benjycui/jsonml-to-react-element/blob/master/src/index.js#L47). It works like `switch` sentence.

Each item in converters is a pair of functions. The first function is a prediction, and the second function is a processor which take JsonML node and return React Component.

## Relative

[jsonml.js](https://github.com/benjycui/jsonml.js) A collection of JsonML tools.

## Liscence

MIT

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