Skip to content

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

License

Notifications You must be signed in to change notification settings

bberak/react-inline-script

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published