react-inline-script

Inject arbitrary javascript and inline <script> tags into your DOM without any headaches

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
react-inline-script
511.2.04 years ago4 years agoMinified + gzip package size for react-inline-script in KB

Readme

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