/use-pipe-ts

Pipe-based useCallback react hook

Primary LanguageTypeScriptMIT LicenseMIT

use-pipe-ts

npm build publish Libraries.io dependency status for latest release Bundlephobia npm

Pipe-based useCallback react hook

Getting started

$ npm i use-pipe-ts

Overview

export function usePipe(...fns) {
  return useCallback(
    pipe(...fns.map((fn) => (typeof fn === 'function' ? fn : subst(...fn)))),
    fns.flat()
  )
}

function subst(fn, ...subs) {
  return (...args) => fn(...subs, ...args)
}

Usage

See test