An open API service indexing awesome lists of open source software.

https://github.com/diffcunha/jsonmltoreact

JsonML to React component converter
https://github.com/diffcunha/jsonmltoreact

jsonml react react-converter

Last synced: about 1 year ago
JSON representation

JsonML to React component converter

Awesome Lists containing this project

README

          

[![Code Climate](https://codeclimate.com/github/diffcunha/jsonmltoreact/badges/gpa.svg)](https://codeclimate.com/github/diffcunha/jsonmltoreact)
[![Test Coverage](https://codeclimate.com/github/diffcunha/jsonmltoreact/badges/coverage.svg)](https://codeclimate.com/github/diffcunha/jsonmltoreact/coverage)

# jsonmltoreact
JsonML to React converter

## Install

```shell
$ npm i --save jsonmltoreact
```

## Examples

```js
import _ from 'lodash';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import JsonmlToReact from 'jsonmltoreact';

// Some random React component
class CustomCompoenent extends React.Component {
render() {
return (


{this.props.header &&

{this.props.header}

}
{this.props.subheader &&

{this.props.subheader}

}
{this.props.children}

);
}
}

// Create instance with custom converters
let jsonmlToReact = new JsonmlToReact({
'custom-tag': (props, data) => ({
type: CustomCompoenent,
props: { ...props, ...data },
}),
'span': props => ({
props: {
className: 'foobar'
}
})
});

// JsonML tree
let jsonml = [
'div', { class: 'container' },
[
'custom-tag', { subheader: 'bar' },
[
'span', 'content'
]
]
];

// Optional data to be passed to converters
let data = {
'header': 'foo',
};

let reactComponent = jsonmlToReact.convert(jsonml, data);

console.log(ReactDOMServer.renderToStaticMarkup(reactComponent));
/*



foo


bar


content


*/
```