0.1.0 • Published 1 year ago

use-fn-cache v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

useFnCache

Cache function in the JSX code. Reduce the unless rerender.

Wrap the function that is the property of component to put it into the cache. The function will be same in multiple rerender, and the unless rerender will be reduced.

The function will be in the JSX code, so you can have the type hint、fluent view and so on.

Install

npm install --save use-fn-cache

Usage

function CacheWithoutDependent() {
  const fn = useFnCache();

  return <Message render={fn('render', () => 'Using cache with no dependent. Never rerender!')}/>;
}

function CacheWithDependent(props: {value: number}) {
  const fn = useFnCache();

  return <Message render={fn('render', () => 'Using cache with value1 as dependent. Rerender when value1 is changed!', [props.value])}/>;
}

License

MIT