16 Replies
Hi @parothia. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To call the
useCustom
hook manually in refine, you need to import it from @refinedev/core
and then use it in your component. The useCustom
hook expects the url
and method
properties, which will be passed to the custom
method from the dataProvider
as parameters. When properties are changed, the useCustom
hook will trigger a new request.
Here is a basic usage example:
In this example, useApiUrl
is used to get the base URL of the API endpoint. The useCustom
hook is then used to send a request to the endpoint. The url
property accepts the endpoint URL, and the method
property accepts the type of method of the endpoint. The config
property accepts values like the headers
for the endpoint, query
parameters, and many more.
For more information, you can refer to the useCustom documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustom/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1149386202403844156> kapa.ai is still learning and improving, please let us know how it did by reacting below
rising-crimsonOP•16mo ago
@kapa.ai
const {
isLoading,
data,
refetch,
} = useCustom<
BankStatementEntryListResponse,
ApiErrorResponse,
BankStatementEntrySearchRequest
>({
url:
${apiUrl}/${apiPaths.bankStatement.entries}
,
method: 'get',
queryOptions: {
enabled: false,
},
config: {
query: {
pageSize: searchRequest.pageSize,
pageNumber: searchRequest.pageNumber,
searchText: searchRequest.searchText,
status: searchRequest.status,
fromDate: searchRequest.fromDate,
toDate: searchRequest.toDate,
bankUuid: searchRequest.bankUuid,
entryType: searchRequest.entryType,
},
},
errorNotification: (error: ApiErrorResponse | undefined) => {
return {
message: t('pages.bankStatement.entriesList.errorNotificationMessage'),
type: 'error',
description: error?.detailedMessage,
};
},
successNotification: false,
});
call this api manuallyLet me check the knowledge base for you. One moment! :books:
national-gold•16mo ago
hello @parothia ,
refine uses react-query under the hood.
I believe this can be helpfull
https://stackoverflow.com/questions/62340697/react-query-how-to-usequery-when-button-is-clicked
----------------------
To call the API manually using the
useCustom
hook in the refine framework, you can use the refetch
function that is returned by the hook. The refetch
function allows you to manually trigger the API call whenever you need it.
In your case, you have disabled the initial API call by setting enabled: false
in queryOptions
. So, you can call the API manually by invoking the refetch
function.
Here is an example of how you can do it:
In this example, refetch()
is used to manually trigger the API call. You can call this function wherever you need to refresh the data.
For more information, you can refer to the useCustom documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustom/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1149386202403844156> kapa.ai is still learning and improving, please let us know how it did by reacting below
rising-crimsonOP•16mo ago
@kapa.ai how to fetch the api with different params
Let me check the knowledge base for you. One moment! :books:
----------------------
To fetch the API with different parameters using the
useCustom
hook in refine, you can pass the new parameters to the refetch
function. The refetch
function accepts an object with the same properties as the useCustom
hook.
Here is an example of how you can do it:
In this example, refetch()
is used to manually trigger the API call with new parameters. You can replace newPageSize
, newPageNumber
, newSearchText
, etc. with your new values.
For more information, you can refer to the useCustom documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustom/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1149386202403844156> kapa.ai is still learning and improving, please let us know how it did by reacting below
rising-crimsonOP•16mo ago
@kapa.ai refetch page
Let me check the knowledge base for you. One moment! :books:
----------------------
To refetch a page using the
useCustom
hook in refine, you can use the refetch
function that is returned by the hook. The refetch
function allows you to manually trigger the API call whenever you need it.
Here is an example of how you can do it:
In this example, refetch()
is used to manually trigger the API call. You can call this function wherever you need to refresh the data.
For more information, you can refer to the useCustom documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustom/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1149386202403844156> kapa.ai is still learning and improving, please let us know how it did by reacting below
rising-crimsonOP•16mo ago
@kapa.ai refetch a page with pagenumber
Let me check the knowledge base for you. One moment! :books:
----------------------
To refetch a page with a specific page number using the
useCustom
hook in refine, you can pass the new page number to the refetch
function. The refetch
function accepts an object with the same properties as the useCustom
hook.
Here is an example of how you can do it:
In this example, refetch()
is used to manually trigger the API call with a new page number. You can replace newPageNumber
with your desired page number.
For more information, you can refer to the useCustom documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustom/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1149386202403844156> kapa.ai is still learning and improving, please let us know how it did by reacting below