Skip to content

Commit b3a97f5

Browse files
committed
v2.0.0
1 parent 5b1179f commit b3a97f5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,6 @@ export function useRenderInfo(name = "Unknown") {
10051005
}
10061006
}
10071007

1008-
const cachedScriptStatuses = {};
1009-
10101008
export function useScript(src, options = {}) {
10111009
const [status, setStatus] = React.useState(() => {
10121010
if (!src) {
@@ -1016,12 +1014,14 @@ export function useScript(src, options = {}) {
10161014
return "loading";
10171015
});
10181016

1017+
const cachedScriptStatuses = React.useRef({});
1018+
10191019
React.useEffect(() => {
10201020
if (!src) {
10211021
return;
10221022
}
10231023

1024-
const cachedScriptStatus = cachedScriptStatuses[src];
1024+
const cachedScriptStatus = cachedScriptStatuses.current[src];
10251025
if (cachedScriptStatus === "ready" || cachedScriptStatus === "error") {
10261026
setStatus(cachedScriptStatus);
10271027
return;
@@ -1055,7 +1055,7 @@ export function useScript(src, options = {}) {
10551055
const setStateFromEvent = (event) => {
10561056
const newStatus = event.type === "load" ? "ready" : "error";
10571057
setStatus(newStatus);
1058-
cachedScriptStatuses[src] = newStatus;
1058+
cachedScriptStatuses.current[src] = newStatus;
10591059
};
10601060

10611061
script.addEventListener("load", setStateFromEvent);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uidotdev/usehooks",
3-
"version": "0.0.5",
3+
"version": "2.0.0",
44
"description": "A collection of Server Component safe React Hooks – from the ui.dev team",
55
"type": "module",
66
"repository": "uidotdev/usehooks",

0 commit comments

Comments
 (0)