convert string to react component
npm install string-to-react  
A tool to convert JSX strings into React Components
```
npm install string-to-react --save-dev
`javascript
import ReactDOM from 'react-dom'
import StringToReact from 'string-to-react'
let s =
ReactDOM.render(StringToReact(s), document.getElementById('container'))
`$3
`javascript
import React from 'react'
import ReactDOM from 'react-dom'
import StringToReact from 'string-to-react'class View extends React.Component {
render() {
return
{this.props.children}
}
}let s =
let transform = function(tagName) {
if (tagName === 'View') return View
return null
}
ReactDOM.render(StringToReact(s, transform), document.getElementById('container'))
`$3
####
function StringToReact(string, [transform])-
string: The JSX string
- transform: Function
- input: tagName:string
- output: FunctionComponent | ComponentClass | string | null
- typescript declare:
`typescript
interface Transform {
(tagName: string): FunctionComponent | ComponentClass | string | null
}
`
- example:
`javascript
import View from './View.jsx'
let transform = function(tagName) {
if (tagName === 'pdiv') return 'div'
else if (tagName === 'View') return View
return null // must return null if no match
}
``