react-inline-script

1.2.0 • Public • Published

react-inline-script

Inject arbitrary javascript and inline <script> tags into your DOM and React app without any hassles.

Usage

import React from 'react'
import Script from "react-inline-script"
 
export default class PageLayout extends React.Component {
  constructor(props) {
    super(props)
  }
 
  render() {
    return (
      <div id="some-content">
        <Script>alert("hi there!")</Script>
      </div>)
    }
}

For multiline scripts, just wrap your contents in {` /* Your script */ `}:

import React from 'react'
import Script from "react-inline-script"
 
export default class PageLayout extends React.Component {
  constructor(props) {
    super(props)
  }
 
  render() {
    return (
      <div id="some-content">
        <Script>
         {`
         const test = true
         if (test)
         alert("howdy!")
         `}
        </Script>
      </div>)
    }
}

Package Sidebar

Install

npm i react-inline-script

Weekly Downloads

1,922

Version

1.2.0

License

MIT

Unpacked Size

9.04 kB

Total Files

4

Last publish

Collaborators

  • bberak