Convert React components to JSON and the other way around, compatible with react typescript
CreateJsx(
<div className='div-class'>
<span style={{color:'black'}} className='span-class'>
this is text
</span>
</div>
) | ⇄ |
CreateJSON({
type: "div",
props: {
className: "div-class",
style: {},
children: [
{
type: "span",
key: null,
ref: null,
props: {
className: "span-class",
style: {
color: "black"
},
children: [
"this is text"
]
}
}
]
},
key: null,
ref: null
}) |
interface NodeJson {
type: string | Function;
key?: string | number | null;
ref?: any;
props: {
className: string;
style?: any;
children: Array<NodeJson | string>;
};
}
npm i jsx-transform-json