File tree 2 files changed +5
-5
lines changed
2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -1005,8 +1005,6 @@ export function useRenderInfo(name = "Unknown") {
1005
1005
}
1006
1006
}
1007
1007
1008
- const cachedScriptStatuses = { } ;
1009
-
1010
1008
export function useScript ( src , options = { } ) {
1011
1009
const [ status , setStatus ] = React . useState ( ( ) => {
1012
1010
if ( ! src ) {
@@ -1016,12 +1014,14 @@ export function useScript(src, options = {}) {
1016
1014
return "loading" ;
1017
1015
} ) ;
1018
1016
1017
+ const cachedScriptStatuses = React . useRef ( { } ) ;
1018
+
1019
1019
React . useEffect ( ( ) => {
1020
1020
if ( ! src ) {
1021
1021
return ;
1022
1022
}
1023
1023
1024
- const cachedScriptStatus = cachedScriptStatuses [ src ] ;
1024
+ const cachedScriptStatus = cachedScriptStatuses . current [ src ] ;
1025
1025
if ( cachedScriptStatus === "ready" || cachedScriptStatus === "error" ) {
1026
1026
setStatus ( cachedScriptStatus ) ;
1027
1027
return ;
@@ -1055,7 +1055,7 @@ export function useScript(src, options = {}) {
1055
1055
const setStateFromEvent = ( event ) => {
1056
1056
const newStatus = event . type === "load" ? "ready" : "error" ;
1057
1057
setStatus ( newStatus ) ;
1058
- cachedScriptStatuses [ src ] = newStatus ;
1058
+ cachedScriptStatuses . current [ src ] = newStatus ;
1059
1059
} ;
1060
1060
1061
1061
script . addEventListener ( "load" , setStateFromEvent ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @uidotdev/usehooks" ,
3
- "version" : " 0 .0.5 " ,
3
+ "version" : " 2 .0.0 " ,
4
4
"description" : " A collection of Server Component safe React Hooks – from the ui.dev team" ,
5
5
"type" : " module" ,
6
6
"repository" : " uidotdev/usehooks" ,
You can’t perform that action at this time.
0 commit comments