ساخت هوک سفارشی مدیریت API در ریاکت
پرامپتی حرفهای برای نوشتن کد یک هوک سفارشی ریاکت با تایپاسکریپت که درخواستهای API را به صورت خودکار مدیریت کرده و حالتهای بارگذاری، خطا و موفقیت را برگرداند.
As a senior frontend engineer, write a custom React hook called `useApi` in TypeScript that simplifies data fetching from REST APIs. The hook should handle the following states automatically: `data` (the fetched data), `error` (any API errors), and `isLoading` (boolean indicating the request status). It must also support an optional `autoFetch` boolean parameter to trigger the request immediately on component mount, and a `dependencies` array to refetch when values change. Use the `AbortController` API to prevent memory leaks when the component unmounts. Provide a usage example of this hook inside a functional React component displaying a list of items from a mock API URL. Ensure the code follows React Hooks rules and is fully typed.