Version: 4.xx.xxSource Code
useApiUrl
useApiUrl
is a React hook that returns the API URL.
- It uses the
getApiUrl
method to get the API URL from thedataProvider
.
It is useful when you want to use the API URL in your custom hooks.
Usage​
The useApiUrl
hook does not expect any parameter. It will run the getApiUrl
method from the dataProvider
and return the result.
import { useCustom, useApiUrl } from "@refinedev/core";
interface PostUniqueCheckResponse {
isAvailable: boolean;
}
const apiUrl = useApiUrl();
const { data, isLoading } = useCustom<PostUniqueCheckResponse>({
url: `${apiUrl}/posts-unique-check`,
method: "get",
config: {
query: {
title: "Foo bar",
},
},
});
API​
Return value​
Description | Type |
---|---|
API URL | string |