diff --git a/src/hooks/useComputed.ts b/src/hooks/useComputed.ts new file mode 100644 index 0000000..87db6c9 --- /dev/null +++ b/src/hooks/useComputed.ts @@ -0,0 +1,17 @@ +import { computed } from "vue" + +const useComputed = (fn: Function) => { + const map = new Map() + + return (...args: any[]) => { + const key = JSON.stringify(args) + + if (map.has(key)) return map.get(key) + + const comput = computed(() => fn(...args)) + map.set(key, comput) + return comput + } +} + +export default useComputed