sensitive-blue
sensitive-blue11mo ago

useCustom filter

hey, is it possible to set filter when using useCustom to get a specific range of dates when fetching a data?
6 Replies
kapa.ai
kapa.ai11mo ago
Hi @Griyan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to set filters when using the useCustom hook in refine. You can pass the config property to the useCustom hook, which accepts values like headers for the endpoint, query parameters, sorters, filters, payloads, and many more. For example, if you want to fetch data within a specific date range, you can pass dateRange values as query parameters into the useCustom hook. Here is an example from the extracts:
const { data, isLoading } = useCustom({
url: `${apiURL}/posts-unique-check`,
method: "get",
config: {
query: {
title: "Foo bar",
},
},
});
const { data, isLoading } = useCustom({
url: `${apiURL}/posts-unique-check`,
method: "get",
config: {
query: {
title: "Foo bar",
},
},
});
In this example, the query parameter is used to filter the data by title. You can modify this to filter by date range instead. 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: ----------------------
kapa.ai
kapa.ai11mo ago
<@907958834901975110> kapa.ai is still learning and improving, please let us know how it did by reacting below
sensitive-blue
sensitive-blue11mo ago
is it possible if i want to fetch the data between "2023-05-01" until "2023-05-18" and set filters to does desired date range? is it possible if i want to fetch the data between "2023-05-01" until "2023-05-18" and set filters to does desired date range? @kapa.ai
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, it is possible to fetch data for a specific date range using the useCustom hook in refine. You can pass the config property to the useCustom hook, which accepts a query parameter. This query parameter can be used to set filters for the desired date range. Here is an example of how you can modify the query parameter to filter data between "2023-05-01" and "2023-05-18":
const { data, isLoading } = useCustom({
url: `${apiURL}/posts-unique-check`,
method: "get",
config: {
query: {
startDate: "2023-05-01",
endDate: "2023-05-18"
},
},
});
const { data, isLoading } = useCustom({
url: `${apiURL}/posts-unique-check`,
method: "get",
config: {
query: {
startDate: "2023-05-01",
endDate: "2023-05-18"
},
},
});
In this example, the query parameter is used to filter the data by a specific date range. The startDate and endDate fields in the query parameter specify the desired date range. Please note that the actual implementation may vary depending on how your API handles date range queries. You should adjust the query parameter to match your API's requirements. 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: ----------------------
kapa.ai
kapa.ai11mo ago
<@907958834901975110> kapa.ai is still learning and improving, please let us know how it did by reacting below
conscious-sapphire
conscious-sapphire11mo ago
Hello @Griyan as bot mentioned, you can pass extra parameters and handle it in your data provider.