queryOptions

I want to hit an Api with a specific route, for exampe, lets say api/user-directories/ for example to show a root directory. how can I use queryOptions on a table to be able to add those query parameters to the query? I'm totally stuck on this. const {tableProps, sorter} = useTable<any>({ initialSorter: [ { field: "id", order: "desc", }, ], initialPageSize: 25, queryOptions: { queryKey: 'path', } });
20 Replies
Omer
Omer2y ago
Hey @rothwulf 👋 , Thanks for reaching out to us. Could this be what you're looking for? https://refine.dev/docs/faq/#how-can-i-request-an-api-with-nested-route
harsh-harlequin
harsh-harlequin2y ago
Thank you very much @Omer. Let me check please and try in my codebase. I really appreciate it. No @Omer It didn't work. when I add the nested route here, I don't hit the api from the backend.
Omer
Omer2y ago
Sorry, I didn't understand exactly what you want to do
harsh-harlequin
harsh-harlequin2y ago
i need to make a query to a route of a Api with this kind of structure for example: api/v1/profile-directories?path=%2F Because I don't know how to pass the query parameters using queryOptions: const {tableProps, sorter} = useTable<any>({ initialSorter: [ { field: "id", order: "desc", }, ], initialPageSize: 25, queryOptions: }); I have no idea about what I should pass in queryOptions for passing that path=%2F query parameter. Sorry if I don't have too much knowledge about react-query, but this is related to React Query.
Omer
Omer2y ago
Aha okay. You can use "metaData" for this. Could you check out this doc? https://refine.dev/docs/faq/#how-i-can-override-specific-function-of-data-providers
FAQ | refine
How can I change the form data before submitting it to the API?
harsh-harlequin
harsh-harlequin2y ago
Sure, thank you very much. I really appreciate your help @Omer
Omer
Omer2y ago
If it doesn't work, just let us know. We will be happy to assist you ⚡️
harsh-harlequin
harsh-harlequin2y ago
Thank you very much. Sorry @Omer I don't really understand how to use it. I didn't sleep all night trying to solve this issue. Something like this:? const {tableProps, sorter} = useTable<any>({ initialSorter: [ { field: "id", order: "desc", }, ], initialPageSize: 25, resource: "<path with query parameters here?", metaData: { httpMethod: "patch", } }); But this requires to modify the App.js and I was asking to only touch the file with the table. and to use queryOptions according to my team.
Omer
Omer2y ago
General Concepts | refine
- refine core is fully independent of UI. So you can use core components and hooks without any UI dependency.
harsh-harlequin
harsh-harlequin2y ago
Sure, but there is not a way to use the queryOptions?
Omer
Omer2y ago
You can't with queryOptions. You can pass data to your dataProvider using metaData 🚀
harsh-harlequin
harsh-harlequin2y ago
Thank you very much @Omer, then, I'll better discuss with my team about this.
harsh-harlequin
harsh-harlequin2y ago
Thank you very much @Omer Hi @Omer can I ask you one more question please?
Omer
Omer2y ago
Yes