Shadcn Hooks

useMemoizedFn

A hook to declare a memoized function

Installation

npx shadcn@latest add @shadcnhooks/use-memoized-fn

API

type noop = (this: any, ...args: any[]) => any

type PickFunction<T extends noop> = (
  this: ThisParameterType<T>,
  ...args: Parameters<T>
) => ReturnType<T>

/**
 * A hook to declare a memoized function
 * @param fn - The function to declare as a memoized function
 * @returns The memoized function
 */
export function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>

Credits

Last updated on

On this page