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>)
    }
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.0
    21,740
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.2.0
    21,740
  • 1.1.1
    3
  • 1.1.0
    2
  • 1.0.0
    2

Package Sidebar

Install

npm i react-inline-script

Weekly Downloads

1,476

Version

1.2.0

License

MIT

Unpacked Size

9.04 kB

Total Files

4

Last publish

Collaborators

  • bberak