From ee56231f02898ec9cf4b982a599e71d5d43bf62e Mon Sep 17 00:00:00 2001 From: xingyu Date: Fri, 11 Aug 2023 20:05:24 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20useRefs=E5=87=BD=E6=95=B0=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E6=B3=9B=E5=9E=8B=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/core/useRefs.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hooks/core/useRefs.ts b/src/hooks/core/useRefs.ts index ec380993..79c280f9 100644 --- a/src/hooks/core/useRefs.ts +++ b/src/hooks/core/useRefs.ts @@ -1,16 +1,20 @@ import type { Ref } from 'vue' import { onBeforeUpdate, ref } from 'vue' -export function useRefs(): [Ref, (index: number) => (el: HTMLElement) => void] { - const refs = ref([]) as Ref +function useRefs(): { refs: Ref; setRefs: (index: number) => (el: T) => void } { + const refs = ref([]) as Ref onBeforeUpdate(() => { refs.value = [] }) - const setRefs = (index: number) => (el: HTMLElement) => { + const setRefs = (index: number) => (el: T) => { refs.value[index] = el } - return [refs, setRefs] + return { + refs, + setRefs, + } } +export { useRefs }