Skip to content

Commit e06e32d

Browse files
authored
feat: add skipInitialOnChange to memo utility (#1088)
1 parent 49334c9 commit e06e32d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/virtual-core/src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export function memo<TDeps extends ReadonlyArray<any>, TResult>(
1010
debug?: () => boolean
1111
onChange?: (result: TResult) => void
1212
initialDeps?: TDeps
13+
skipInitialOnChange?: boolean
1314
},
1415
) {
1516
let deps = opts.initialDeps ?? []
1617
let result: TResult | undefined
18+
let isInitial = true
1719

1820
function memoizedFunction(): TResult {
1921
let depTime: number
@@ -62,7 +64,11 @@ export function memo<TDeps extends ReadonlyArray<any>, TResult>(
6264
)
6365
}
6466

65-
opts?.onChange?.(result)
67+
if (opts?.onChange && !(isInitial && opts.skipInitialOnChange)) {
68+
opts.onChange(result)
69+
}
70+
71+
isInitial = false
6672

6773
return result
6874
}

0 commit comments

Comments
 (0)