react-script-hook
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -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 @@ }; |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10215
78