0.2.6 • Published 7 years ago
jsonml-to-react-component v0.2.6
jsonml-to-react-component
To convert JsonML to React Component.
Installation
npm install --save jsonml-to-react-component
Usage
Basic:
const ReactDOM = require('react-dom');
const toReactComponent = require('jsonml-to-react-component');
const title = [
'h1',
'Hello world!',
];
ReactDOM.render(toReactComponent(title), document.getElementById('content'));
With converters:
const React = require('react');
const ReactDOM = require('react-dom');
const toReactComponent = require('jsonml-to-react-component');
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) => toReactComponent(child, html5to4))
)
],
...
];
ReactDOM.render(
toReactComponent(website, html5to4),
document.getElementById('content')
);
API
toReactComponent(jsonml: Object , converters: Array): React.Component
To convert JsonML to React Component with converters.
converters: Array[PairFunction, Function]
Converters which are passed to toReactComponent
will concat with default converters. 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 A collection of JsonML tools.
Liscence
MIT
0.2.6
7 years ago
0.2.5
7 years ago
0.2.4
7 years ago
0.2.3
8 years ago
0.2.2
8 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.10
8 years ago
0.1.9
8 years ago
0.1.8
8 years ago
0.1.7
8 years ago
0.1.6
8 years ago
0.1.5
8 years ago
0.1.4
8 years ago
0.1.3
8 years ago
0.1.2
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago
0.1.0-beta
8 years ago