We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db773da commit b52e8e0Copy full SHA for b52e8e0
src/hooks/useEffect.ts
@@ -0,0 +1,18 @@
1
+import * as React from 'react';
2
+
3
+/** As `React.useEffect` but pass origin value in callback and not need care deps length change. */
4
+export default function useEffect(
5
+ callback: (prevDeps: any[]) => void,
6
+ deps: any[],
7
+) {
8
+ const prevRef = React.useRef(deps);
9
+ React.useEffect(() => {
10
+ if (
11
+ deps.length !== prevRef.current.length ||
12
+ deps.some((dep, index) => dep !== prevRef.current[index])
13
+ ) {
14
+ callback(prevRef.current);
15
+ }
16
+ prevRef.current = deps;
17
+ });
18
+}
0 commit comments