Skip to content

gihanrangana/react-jsxstring-to-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React JSXString to React Component

npm version ts version github release license NPM Downloads

react-jsxstring-to-react is a plugin for React to generate jsx component using strings. follow this example

npm install react-jsxstring-to-react

or

yarn add react-jsxstring-to-react

const jsxString = `<div className="outer">
    <p className="test" style={{"color":"#f00"}}>Your Content</p>
</div>`

function App () {
    const [elements, setElements] = useState([])

    const jsx = useJSX(jsxString)

    useEffect(() => {
        setElements(jsx.convert())
    }, [])

    return (
        <div>
            {elements && elements.map(e => {
                return e;
            })}
        </div>
    )
}

License

Copyright © 2023 Gihan Rangana Released under the MIT license.