@safe-global/safe-react-hooks
Version:
A collection of React Hooks that facilitates the interaction of React apps with Safe Smart Accounts
19 lines • 626 B
JavaScript
import { useEffect, useState } from 'react';
/**
* Hook that memoizes the result of an async function.
* @param factory Async function of which the result should be memoized.
* @param deps Dependency list
* @returns Current result or `undefined` if not available.
*/
export function useAsyncMemo(factory, deps) {
const [result, setResult] = useState(undefined);
useEffect(() => {
factory().then((newResult) => {
if (newResult !== result) {
setResult(newResult);
}
});
}, [...deps, factory]);
return result;
}
//# sourceMappingURL=useAsyncMemo.js.map