create-memo
v4.7.0arrow_drop_downv4.7.0
STATUS
Passing
DOWNLOADS
42
VISIBILITY
Public
PUBLISHED
6 years ago
SIZE
N/A
1 contributor
Like
Install create-memo as a package?
Copied
npm i @bit/giladshoham.react-hooks.use.create-memo
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
and packages in Bit or NPM to the example. any of the 1 million componentstoggle layout
chevron_left
chevron_right
createMemo
Hook factory, receives a function to be memoized, returns a memoized React hook, which receives the same arguments and returns the same result as the original function.
Usage
import {createMemo} from 'react-use';
const fibonacci = n => {
if (n === 0) return 1;
if (n === 1) return 2;
return fibonacci(n - 1) + fibonacci(n - 2);
};
const useMemoFibonacci = createMemo(fibonacci);
const Demo = () => {
const result = useMemoFibonacci(10);
return (
<div>
fib(10) = {result}
</div>
);
};
Reference
const useMemoFn = createMemo(fn);