Skip to content

Commit 82d0a1a

Browse files
committed
chore: adjust logic
1 parent a940494 commit 82d0a1a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/PickerInput/hooks/useDelayState.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEvent, useControlledState } from '@rc-component/util';
1+
import { useEvent, useControlledState, useMergedState } from '@rc-component/util';
22
import raf from '@rc-component/util/lib/raf';
33
import 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);

0 commit comments

Comments
 (0)