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

react-script-hook

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-script-hook - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

15

lib/use-script.js

@@ -17,11 +17,11 @@ "use strict";

var src = _a.src, _b = _a.checkForExisting, checkForExisting = _b === void 0 ? false : _b, attributes = __rest(_a, ["src", "checkForExisting"]);
var _c = react_1.useState(Boolean(src)), loading = _c[0], setLoading = _c[1];
var _d = react_1.useState(null), error = _d[0], setError = _d[1];
react_1.useEffect(function () {
var _c = (0, react_1.useState)(Boolean(src)), loading = _c[0], setLoading = _c[1];
var _d = (0, react_1.useState)(null), error = _d[0], setError = _d[1];
(0, react_1.useEffect)(function () {
if (!isBrowser || !src)
return;
if (checkForExisting) {
var existing = document.querySelectorAll("script[src=\"" + src + "\"]");
if (existing.length > 0) {
setLoading(false);
var existing = document.querySelector("script[src=\"" + src + "\"]");
if (existing) {
setLoading(existing.getAttribute('data-status') === 'loading');
return;

@@ -32,2 +32,3 @@ }

scriptEl.setAttribute('src', src);
scriptEl.setAttribute('data-status', 'loading');
Object.keys(attributes).forEach(function (key) {

@@ -42,5 +43,7 @@ if (scriptEl[key] === undefined) {

var handleLoad = function () {
scriptEl.setAttribute('data-status', 'ready');
setLoading(false);
};
var handleError = function (error) {
scriptEl.setAttribute('data-status', 'error');
setError(error);

@@ -47,0 +50,0 @@ };

6

package.json
{
"name": "react-script-hook",
"version": "1.4.1",
"version": "1.5.0",
"description": "React hook to dynamically load an external script and know when its loaded",

@@ -34,3 +34,3 @@ "keywords": [

"@testing-library/react-hooks": "^7.0.0",
"@types/jest": "^26.0.23",
"@types/jest": "^27.0.1",
"@types/react": "^17.0.11",

@@ -59,2 +59,2 @@ "@types/react-dom": "^17.0.7",

}
}
}

Sorry, the diff of this file is not supported yet

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