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) {
14021402 return [ localState , handleSetState ] ;
14031403}
14041404
1405- const cachedScriptStatuses = { } ;
1406-
14071405export function useScript ( src , options = { } ) {
14081406 const [ status , setStatus ] = React . useState ( ( ) => {
14091407 if ( ! src ) {
@@ -1413,12 +1411,14 @@ export function useScript(src, options = {}) {
14131411 return "loading" ;
14141412 } ) ;
14151413
1414+ const cachedScriptStatuses = React . useRef ( { } ) ;
1415+
14161416 React . useEffect ( ( ) => {
14171417 if ( ! src ) {
14181418 return ;
14191419 }
14201420
1421- const cachedScriptStatus = cachedScriptStatuses [ src ] ;
1421+ const cachedScriptStatus = cachedScriptStatuses . current [ src ] ;
14221422 if ( cachedScriptStatus === "ready" || cachedScriptStatus === "error" ) {
14231423 setStatus ( cachedScriptStatus ) ;
14241424 return ;
@@ -1452,7 +1452,7 @@ export function useScript(src, options = {}) {
14521452 const setStateFromEvent = ( event ) => {
14531453 const newStatus = event . type === "load" ? "ready" : "error" ;
14541454 setStatus ( newStatus ) ;
1455- cachedScriptStatuses [ src ] = newStatus ;
1455+ cachedScriptStatuses . current [ src ] = newStatus ;
14561456 } ;
14571457
14581458 script . addEventListener ( "load" , setStateFromEvent ) ;
You can’t perform that action at this time.
0 commit comments