0.0.5 • Published 7 months ago

astring-react-create-element v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Generate React.createElement() code from JSX AST with astring

Credits to TroyAlford/react-jsx-parser for parts of the code and thanks to Qard/astring-jsx for inspiration

  1. Why use this plugin instead of astring-jsx or other options ? This plugins generates React.createElement that are compatible with React-Native.

Install

npm install astring-react-create-element
# or yarn
yarn add astring-react-create-element

Usage

Example with astring default generator:

import astringReactCreateElement from 'astring-react-create-element';
import * as astring from 'astring';

const formattedCode = astring.generate(ast, {
    generator: astringReactCreateElement(astring.GENERATOR),
});

Example with custom generator:

import astringReactCreateElement from 'astring-react-create-element';
import * as astring from 'astring';

const customGenerator = Object.assign({}, astringReactCreateElement(astring.GENERATOR), {
    JSXFragment: (node, state) => {
        customGenerator['JSXElement'](node, state);
    },
});
const formattedCode = astring.generate(ast, {
    generator: customGenerator,
});
0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago