コンテンツへスキップ

createUnrefFn

カテゴリ
エクスポートサイズ
166 B
最終変更日
2年前
関連

refと生の値を引数として受け付けるプレーンな関数を生成します。変換されていない関数が返すのと同じ値を、適切な型付けで返します。

ヒント

適切なツールを使用していることを確認してください。引数の変更ごとに関数を評価したい場合、reactifyを使用する方が適切な場合があります。

使用方法

ts
import { createUnrefFn } from '@vueuse/core'
import { ref } from 'vue'

const url = ref('https://httpbin.org/post')
const data = ref({ foo: 'bar' })

function post(url, data) {
  return fetch(url, { data })
}
const unrefPost = createUnrefFn(post)

post(url, data) /* ❌ Will throw an error because the arguments are refs */
unrefPost(url, data) /* ✔️ Will Work because the arguments will be auto unref */

型宣言

typescript
export type UnrefFn<T> = T extends (...args: infer A) => infer R
  ? (
      ...args: {
        [K in keyof A]: MaybeRef<A[K]>
      }
    ) => R
  : never
/**
 * Make a plain function accepting ref and raw values as arguments.
 * Returns the same value the unconverted function returns, with proper typing.
 */
export declare function createUnrefFn<T extends Function>(fn: T): UnrefFn<T>

ソース

ソースコードドキュメント

コントリビューター

Anthony Fu
Anthony Fu
Stanley Horwood

変更ログ

最近の変更はありません

MITライセンスの下でリリースされています。