Skip to content

Commit 5da4cc4

Browse files
authored
chore: optimize code by adding depsEqual function (#2216)
1 parent 87b3ade commit 5da4cc4

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

packages/hooks/src/createDeepCompareEffect/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { useRef } from 'react';
22
import type { DependencyList, useEffect, useLayoutEffect } from 'react';
3-
import isEqual from 'lodash/isEqual';
3+
import { depsEqual } from '../utils/depsEqual';
44

55
type EffectHookType = typeof useEffect | typeof useLayoutEffect;
66
type CreateUpdateEffect = (hook: EffectHookType) => EffectHookType;
77

8-
const depsEqual = (aDeps: DependencyList = [], bDeps: DependencyList = []) => {
9-
return isEqual(aDeps, bDeps);
10-
};
11-
128
export const createDeepCompareEffect: CreateUpdateEffect = (hook) => (effect, deps) => {
139
const ref = useRef<DependencyList>();
1410
const signalRef = useRef<number>(0);

packages/hooks/src/utils/depsEqual.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { DependencyList } from 'react';
2+
import isEqual from 'lodash/isEqual';
3+
4+
export const depsEqual = (aDeps: DependencyList = [], bDeps: DependencyList = []) =>
5+
isEqual(aDeps, bDeps);

packages/hooks/src/utils/useDeepCompareWithTarget.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import isEqual from 'lodash/isEqual';
21
import type { DependencyList, EffectCallback } from 'react';
32
import { useRef } from 'react';
43
import type { BasicTarget } from './domTarget';
54
import useEffectWithTarget from './useEffectWithTarget';
6-
7-
const depsEqual = (aDeps: DependencyList, bDeps: DependencyList = []) => {
8-
return isEqual(aDeps, bDeps);
9-
};
5+
import { depsEqual } from './depsEqual';
106

117
const useDeepCompareEffectWithTarget = (
128
effect: EffectCallback,

0 commit comments

Comments
 (0)