Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benadam11 committed May 30, 2023
1 parent 5b1179f commit b3a97f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -1005,8 +1005,6 @@ export function useRenderInfo(name = "Unknown") {
}
}

const cachedScriptStatuses = {};

export function useScript(src, options = {}) {
const [status, setStatus] = React.useState(() => {
if (!src) {
Expand All @@ -1016,12 +1014,14 @@ export function useScript(src, options = {}) {
return "loading";
});

const cachedScriptStatuses = React.useRef({});

React.useEffect(() => {
if (!src) {
return;
}

const cachedScriptStatus = cachedScriptStatuses[src];
const cachedScriptStatus = cachedScriptStatuses.current[src];
if (cachedScriptStatus === "ready" || cachedScriptStatus === "error") {
setStatus(cachedScriptStatus);
return;
Expand Down Expand Up @@ -1055,7 +1055,7 @@ export function useScript(src, options = {}) {
const setStateFromEvent = (event) => {
const newStatus = event.type === "load" ? "ready" : "error";
setStatus(newStatus);
cachedScriptStatuses[src] = newStatus;
cachedScriptStatuses.current[src] = newStatus;
};

script.addEventListener("load", setStateFromEvent);
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@uidotdev/usehooks",
"version": "0.0.5",
"version": "2.0.0",
"description": "A collection of Server Component safe React Hooks – from the ui.dev team",
"type": "module",
"repository": "uidotdev/usehooks",
Expand Down

0 comments on commit b3a97f5

Please sign in to comment.