File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1- import  {  useEvent ,  useControlledState  }  from  '@rc-component/util' ; 
1+ import  {  useEvent ,  useControlledState ,   useMergedState  }  from  '@rc-component/util' ; 
22import  raf  from  '@rc-component/util/lib/raf' ; 
33import  React  from  'react' ; 
44
@@ -13,6 +13,14 @@ export default function useDelayState<T>(
1313) : [ state : T ,  setState : ( nextState : T ,  immediately ?: boolean )  =>  void ]  { 
1414  const  [ state ,  setState ]  =  useControlledState < T > ( defaultValue ,  value ) ; 
1515
16+   // Need force update to ensure React re-render 
17+   const  [ ,  forceUpdate ]  =  React . useState ( { } ) ; 
18+ 
19+   const  triggerUpdate  =  useEvent ( ( nextState : T )  =>  { 
20+     setState ( nextState ) ; 
21+     forceUpdate ( { } ) ; 
22+   } ) ; 
23+ 
1624  const  nextValueRef  =  React . useRef < T > ( value ) ; 
1725
1826  // ============================= Update ============================= 
@@ -22,7 +30,7 @@ export default function useDelayState<T>(
2230  } ; 
2331
2432  const  doUpdate  =  useEvent ( ( )  =>  { 
25-     setState ( nextValueRef . current ) ; 
33+     triggerUpdate ( nextValueRef . current ) ; 
2634
2735    if  ( onChange  &&  state  !==  nextValueRef . current )  { 
2836      onChange ( nextValueRef . current ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments