apps/mantine.dev/src/pages/hooks/use-fetch.mdx
import { UseFetchDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.useFetch);
The useFetch hook sends a GET request to the specified URL and returns the response data, loading state, error,
refetch and abort functions.
interface UseFetchOptions extends RequestInit {
autoInvoke?: boolean;
}
interface UseFetchReturnValue<T> {
data: T | null;
loading: boolean;
error: Error | null;
refetch: () => Promise<any>;
abort: () => void;
}
function useFetch<T>(
url: string,
options?: UseFetchOptions,
): UseFetchReturnValue<T>
UseFetchOptions and UseFetchReturnValue types are exported from the @mantine/hooks package;
you can import them in your application:
import type { UseFetchOptions, UseFetchReturnValue } from '@mantine/hooks';