use-params-memo
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Parameterized React hooks

version minzipped size downloads

useParamsMemo is an implementation of React's useMemo that applies its dependency array as the arguments to its function.

This allows the memoization function to easily be abstracted away, code split, and unit tested as a standalone module with no concerns of React or hooks.

This decreases common errors when the memoization function uses stateful variables that are not included in the dependency array.

This results in significantly shorter hooks and more maintainable code.

Install

  • npm install use-params-memo or
  • yarn add use-params-memo

Use

import useParamsMemo from 'use-params-memo';

const add = (a, b) => a + b;

export default function useOurSum({ mine, yours }) {
  // Equivalent to: useMemo(() => add(mine, yours), [mine, yours])
  return useParamsMemo(add, [mine, yours]);
}

Contributing

  • yarn set version latest
  • yarn up * @*/*
  • yarn add --dev @yarnpkg/sdks
  • yarn sdks vscode

Readme

Keywords

none

Package Sidebar

Install

npm i use-params-memo

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.52 kB

Total Files

6

Last publish

Collaborators

  • charlesstover