import { useEffect, useState } from 'react'; /** * Handle asynchronous operations with memoization. * It only re-executes the async function when dependencies change. */ export const useAsyncMemo = ( asyncFn: () => Promise, dependencies: any[], ): T => { const [value, setValue] = useState(); useEffect(() => { let isMounted = true; asyncFn().then((result) => { if (isMounted) setValue(result); }); return () => { isMounted = false; }; }, dependencies); return value as T; };