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' ;
2
2
import raf from '@rc-component/util/lib/raf' ;
3
3
import React from 'react' ;
4
4
@@ -13,6 +13,14 @@ export default function useDelayState<T>(
13
13
) : [ state : T , setState : ( nextState : T , immediately ?: boolean ) => void ] {
14
14
const [ state , setState ] = useControlledState < T > ( defaultValue , value ) ;
15
15
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
+
16
24
const nextValueRef = React . useRef < T > ( value ) ;
17
25
18
26
// ============================= Update =============================
@@ -22,7 +30,7 @@ export default function useDelayState<T>(
22
30
} ;
23
31
24
32
const doUpdate = useEvent ( ( ) => {
25
- setState ( nextValueRef . current ) ;
33
+ triggerUpdate ( nextValueRef . current ) ;
26
34
27
35
if ( onChange && state !== nextValueRef . current ) {
28
36
onChange ( nextValueRef . current ) ;
You can’t perform that action at this time.
0 commit comments