Files
Rocketmc/apps/frontend/src/composables/auto-ref.ts
Evan Song abec2e48d4 Add TailwindCSS (#1252)
* Setup TailwindCSS

* Fully setup configuration

* Refactor some tailwind variables
2024-07-06 20:57:32 -07:00

14 lines
484 B
TypeScript

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);
}