Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@newsteam/use-script

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

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)

  • 0.0.13
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by20%
Maintainers
0
Weekly downloads
 
Created
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

Package last updated on 17 Sep 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc