String to React
A tool to convert JSX strings into React Components
Installation:
npm install string-to-react --save-dev
Usage:
let s = `<div>hi</div>`ReactDOM
Customized Component
Component { return <div ...thisprops>thispropschildren</div> } let s = `<View style={{fontSize: '12px'}}>hi</View>` let { if tagName === 'View' return View return null} ReactDOM
Api
function StringToReact(string, [transform])
string
: The JSX stringtransform
:Function
- input:
tagName:string
- output:
FunctionComponent | ComponentClass | string | null
- typescript declare:
- example:let {if tagName === 'pdiv' return 'div'else if tagName === 'View' return Viewreturn null // must return null if no match}
- input: