Socket
Socket
Sign inDemoInstall

@newsteam/use-script

Package Overview
Dependencies
4
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @newsteam/use-script

[![License](https://img.shields.io/npm/l/@newsteam/use-script.svg)](https://github.com/feight/newsteam/blob/master/LICENSE) [![npm package](https://img.shields.io/npm/v/@newsteam/use-script/latest.svg)](https://www.npmjs.com/package/@newsteam/use-script)


Version published
Weekly downloads
3
Maintainers
4
Created
Weekly downloads
 

Readme

Source

@newsteam/use-script

License npm package npm downloads

Loads a script and returns a status when the script is loaded or fails to load.

Example

import {useScript} from "@newsteam/use-script";

const MyComponent = () => {
    const script = useScript("//platform.instagram.com/en_US/embeds.js");

    if (script === "ready") {
        return <InstagramWidget />;
    }
};

Edge Cases

Sometimes a script will use an interal reference the id of the script tag and not function correctly if that id attribute is not set.

This hook supports adding an id to the script tag it generates.

import {useScript} from "@newsteam/use-script";

const MyComponent = () => {
    const script = useScript({
        src: "https://e.infogram.com/js/dist/embed-loader-min.js",
        id: "infogram-async"
    });

    if (script === "ready") {
        return <InfogramWidget />;
    }
};

Sometimes a script will modify the dom at the location of the script tag. This is common with widget embed scripts.

This hook supports appending the script tag into a custom parent instead of the head of the document.

import {useScript} from "@newsteam/use-script";

const MyComponent = ({parent}) => {
    const script = useScript({
        src: "https://e.infogram.com/js/dist/embed-loader-min.js",
        parent
    });

    if (script === "ready") {
        return <InfogramWidget />;
    }
};

FAQs

Last updated on 27 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc