shadcn-ahooks

useLockFn

Add lock to an async function to prevent parallel executions.

Overview

Add lock to an async function to prevent parallel executions.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLockFn.json

Add lock to an async function to prevent parallel executions.

Examples

Basic usage

API

function useLockFn<P extends any[] = any[], V = any>(
  fn: (...args: P) => Promise<V>
): fn: (...args: P) => Promise<V | undefined>;

Result

PropertyDescriptionType
fnThe async function with lock(...args: any[]) => Promise<any>

Params

PropertyDescriptionTypeDefault
fnAn async function(...args: any[]) => Promise<any>-

On this page