File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -1200,16 +1200,22 @@ export function useSessionStorage(key, initialValue) {
12001200    [ key ,  store ] 
12011201  ) ; 
12021202
1203+   const  initialValueRef  =  useRef ( initialValue ) 
1204+ 
12031205  React . useEffect ( ( )  =>  { 
12041206    if  ( 
12051207      getSessionStorageItem ( key )  ===  null  && 
12061208      typeof  initialValue  !==  "undefined" 
12071209    )  { 
1208-       setSessionStorageItem ( key ,  initialValue ) ; 
1210+       setSessionStorageItem ( key ,  initialValueRef . current ) ; 
12091211    } 
1210-   } ,  [ key ,   initialValue ] ) ; 
1212+   } ,  [ key ] ) ; 
12111213
1212-   return  [ store  ? JSON . parse ( store )  : initialValue ,  setState ] ; 
1214+   const  result  =  useMemo ( ( )  =>  { 
1215+     return  store  ? JSON . parse ( store )  : initialValueRef . current 
1216+   } ,  [ store ] ) 
1217+ 
1218+   return  [ result ,  setState ] ; 
12131219} 
12141220
12151221export  function  useSet ( values )  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments