react-inner-html-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

About This Lib

This lib was created to write text as html on component, "But it doesn't already exist?", yes, exist the method default on react, but this method don't execute script JavaScript, then, i created for this execution!

How did the idea come about?

In one of the projects I'm working on, the need arose to create posts, which would be used to run HTML and JS; Where the author, in addition to using the text to create the posts, can create the html to shape the page, in addition to using the js to make it more interactive;

However, React only has the way of writing the html, it does not run the JS, for this and others I created such a project, to write and run the JS;

How use?

First install the lib:

$ npm i react-inner-html-js
function MyComponent(){
    const content = `
        <h2>Hello World!</h2>
        <script>
            console.log("JavaScript Work!")
        </script>
    `

    return (
        <div>
            <h1>Post</h1>
            <InnerHTML content={content}/>
        </div>
    )
}

This write content on a div, for execute in another tag use:

function MyComponent(){
    const content = `
        <h2>Hello World!</h2>
        <script>
            console.log("JavaScript Work!")
        </script>
    `

    // The prop rf is required
    const MySection = ({rf})=> <section ref={rf}></section>

    return (
        <div>
            <h1>Post</h1>
            <InnerHTML Feather={MySection} content={content}/>
        </div>
    )
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-inner-html-js

Weekly Downloads

2

Version

1.0.4

License

none

Unpacked Size

64.8 kB

Total Files

7

Last publish

Collaborators

  • jeff_dev_it