|
Download react-use/docs/createMemo.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 607 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/createMemo.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/createMemo.md
-
curl -L -o createMemo.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/createMemo.md
607 Bytes
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 0;
if (n === 1) return 1;
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);