equal-aqua
equal-aqua7mo ago

useCustom get request not sending meta populate params (Strapi)

Hi, i'm trying to make a request to get a resource with a relation populated trough the useCustom hook to make the request. But when the browser sends the request, there are no populate fields param settedf in the request. I'm using Strapi dataProvider backend. This is the useCustom call
const { data } = useCustom<Slot>({
url: `${apiUrl}/slots/${slotId}`,
method: 'get',
meta: {
populate: ['jobRole']
},
queryOptions: {
enabled: !!slotId
}
});
const { data } = useCustom<Slot>({
url: `${apiUrl}/slots/${slotId}`,
method: 'get',
meta: {
populate: ['jobRole']
},
queryOptions: {
enabled: !!slotId
}
});
this is the request that the browser sends to the API: - url: GET http://localhost:1337/api/slots/69? - response:
{
"data": {
"id": 69,
"attributes": {
"createdAt": "2023-11-01T18:13:43.973Z",
"updatedAt": "2023-11-01T18:13:43.973Z",
"publishedAt": "2023-11-01T18:13:43.973Z"
}
},
"meta": {}
}"
{
"data": {
"id": 69,
"attributes": {
"createdAt": "2023-11-01T18:13:43.973Z",
"updatedAt": "2023-11-01T18:13:43.973Z",
"publishedAt": "2023-11-01T18:13:43.973Z"
}
},
"meta": {}
}"
6 Replies
kapa.ai
kapa.ai7mo ago
Hi @kraloz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, it seems like you're trying to populate the jobRole field in your slots resource using the useCustom hook. However, the useCustom hook does not support the meta property for populating fields. Instead, you can use the useTable or useList hooks to populate fields in your resources. These hooks support the meta property, which you can use to specify the fields you want to populate. Here's an example of how you can use the useTable hook to populate the jobRole field in your slots resource:
import { useTable } from "@refinedev/react-table";

const { getHeaderGroups, getRowModel, refineCore: { setCurrent, pageCount, current } } = useTable({
columns,
refineCoreProps: {
meta: {
populate: ["jobRole"],
},
},
});
import { useTable } from "@refinedev/react-table";

const { getHeaderGroups, getRowModel, refineCore: { setCurrent, pageCount, current } } = useTable({
columns,
refineCoreProps: {
meta: {
populate: ["jobRole"],
},
},
});
And here's an example of how you can use the useList hook:
const { data: dataSessions } = useList<ISession>({
resource: "slots",
filters: [
{
field: "populate",
operator: "eq",
value: "jobRole",
},
],
});
const { data: dataSessions } = useList<ISession>({
resource: "slots",
filters: [
{
field: "populate",
operator: "eq",
value: "jobRole",
},
],
});
This will send a request to /slots?populate=jobRole. For more information, you can refer to the Refine documentation (https://refine.dev/docs). Sources: - Refine Documentation (https://refine.dev/docs/packages/documentation/data-providers/strapi-v4/) - Refine Blog (https://refine.dev/blog/react-admin-panel/) - Discord Support Thread (https://discord.com/channels/837692625737613362/1160933198507823227) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@240270957686554624> kapa.ai is still learning and improving, please let us know how it did by reacting below
equal-aqua
equal-aqua7mo ago
The useCustom hook docs shows the meta option support: https://refine.dev/docs/api-reference/core/hooks/data/useCustom/#meta
useCustom | refine
useCustom is used to send custom query requests using the Tanstack Query advantages. It is an extended version of TanStack Query's useQuery and not only supports all features of the mutation but also adds some extra features.
equal-aqua
equal-aqua7mo ago
I found that the useOne hook is much better situable for this use case
equal-aqua
equal-aqua7mo ago
useOne | refine
useOne is an extended version of TanStack Query's useQuery that supports all of its features and adds some more.
equal-aqua
equal-aqua7mo ago
but the question is still unresolved