Last active
May 30, 2023 04:50
-
-
Save jeongtae/588627882a464effa070c16f1c47e788 to your computer and use it in GitHub Desktop.
[Vue composable] This composable helps the argument of Vue Composable guarantee Vue Reactivity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MaybeRef } from '@vueuse/core'; | |
import { computed, ComputedRef, unref } from 'vue'; | |
/** | |
* Union generic type of `Raw Value` | `Ref Value`, `Value Getter`. | |
* `Raw 값`, `Ref 값`, `값 Getter` 타입을 모두 포용하는 Union Generic 타입입니다. | |
*/ | |
export type ReactiveParam<T> = T extends Function ? never : MaybeRef<T> | (() => T); | |
/** Unwraps `ReactiveParam<T>` and converts it to `ComputedRef<T>`. | |
* This function helps the argument of Vue Composable guarantee Vue Reactivity. | |
* `ReactiveParam<T>` 타입을 unwrap하여 `ComputedRef<T>`로 만들어줍니다. | |
* 이는 Vue Composable 함수 매개변수가 Vue Reactivity를 보장하도록 돕습니다. | |
* @link https://vuejs.org/guide/reusability/composables.html#input-arguments | |
*/ | |
export function useReactiveParam<T>(param: ReactiveParam<T>): ComputedRef<T> { | |
return computed(() => (param instanceof Function ? param() : unref(param))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment