forked from didirus/AstralRinth
Migrate to Turborepo (#1251)
This commit is contained in:
13
apps/frontend/src/composables/auto-ref.ts
Normal file
13
apps/frontend/src/composables/auto-ref.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export type AutoRef<T> = [T] extends [(...args: any[]) => any]
|
||||
? Ref<T> | (() => T)
|
||||
: T | Ref<T> | (() => T)
|
||||
|
||||
/**
|
||||
* Accepts a value directly, a ref with the value or a getter function and returns a Vue ref.
|
||||
* @param value The value to use.
|
||||
* @returns Either the original or newly created ref.
|
||||
*/
|
||||
export function useAutoRef<T>(value: AutoRef<T>): Ref<T> {
|
||||
if (typeof value === 'function') return computed(() => value())
|
||||
return isRef(value) ? value : ref(value as any)
|
||||
}
|
||||
Reference in New Issue
Block a user