Skip to content

Commit 82a5ea6

Browse files
committed
refactor: replace hooks with rc-util useState
1 parent 485c091 commit 82a5ea6

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@babel/runtime": "^7.11.1",
4747
"classnames": "^2.2.1",
4848
"rc-resize-observer": "^1.0.0",
49-
"rc-util": "^5.15.0"
49+
"rc-util": "^5.19.2"
5050
},
5151
"devDependencies": {
5252
"@types/classnames": "^2.2.9",

src/hooks/useBatchFrameState.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useRef, useState, useEffect } from 'react';
1+
import { useRef } from 'react';
22
import raf from 'rc-util/lib/raf';
3+
import useState from 'rc-util/lib/hooks/useState';
34

45
/**
56
* State generate. Return a `setState` but it will flush all state with one render to save perf.
@@ -8,17 +9,9 @@ import raf from 'rc-util/lib/raf';
89
export function useBatchFrameState() {
910
const [, forceUpdate] = useState({});
1011
const statesRef = useRef<any[]>([]);
11-
const destroyRef = useRef<boolean>(false);
1212
let walkingIndex = 0;
1313
let beforeFrameId: number = 0;
1414

15-
useEffect(
16-
() => () => {
17-
destroyRef.current = true;
18-
},
19-
[],
20-
);
21-
2215
function createState<T>(
2316
defaultValue: T,
2417
): [T, (value: T | ((origin: T) => T)) => void] {
@@ -41,9 +34,7 @@ export function useBatchFrameState() {
4134

4235
// Flush with batch
4336
beforeFrameId = raf(() => {
44-
if (!destroyRef.current) {
45-
forceUpdate({});
46-
}
37+
forceUpdate({}, true);
4738
});
4839
}
4940

0 commit comments

Comments
 (0)