File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -1402,8 +1402,6 @@ export function useSessionStorage(key, initialValue) {
1402
1402
return [ localState , handleSetState ] ;
1403
1403
}
1404
1404
1405
- const cachedScriptStatuses = { } ;
1406
-
1407
1405
export function useScript ( src , options = { } ) {
1408
1406
const [ status , setStatus ] = React . useState ( ( ) => {
1409
1407
if ( ! src ) {
@@ -1413,12 +1411,14 @@ export function useScript(src, options = {}) {
1413
1411
return "loading" ;
1414
1412
} ) ;
1415
1413
1414
+ const cachedScriptStatuses = React . useRef ( { } ) ;
1415
+
1416
1416
React . useEffect ( ( ) => {
1417
1417
if ( ! src ) {
1418
1418
return ;
1419
1419
}
1420
1420
1421
- const cachedScriptStatus = cachedScriptStatuses [ src ] ;
1421
+ const cachedScriptStatus = cachedScriptStatuses . current [ src ] ;
1422
1422
if ( cachedScriptStatus === "ready" || cachedScriptStatus === "error" ) {
1423
1423
setStatus ( cachedScriptStatus ) ;
1424
1424
return ;
@@ -1452,7 +1452,7 @@ export function useScript(src, options = {}) {
1452
1452
const setStateFromEvent = ( event ) => {
1453
1453
const newStatus = event . type === "load" ? "ready" : "error" ;
1454
1454
setStatus ( newStatus ) ;
1455
- cachedScriptStatuses [ src ] = newStatus ;
1455
+ cachedScriptStatuses . current [ src ] = newStatus ;
1456
1456
} ;
1457
1457
1458
1458
script . addEventListener ( "load" , setStateFromEvent ) ;
You can’t perform that action at this time.
0 commit comments