how to pass additional "meta" for resources to dataProvider?
I'm writing a new dataProfider for the WordPress REST API.
I need to pass additional parameters for the resource to the dataProvider.
Thans to the help of kapa.ai in this thread: https://discord.com/channels/837692625737613362/1093124784801468487
I tried to add them as
meta
in <Refine resources{}>
but I can't get it in the dataProvider.
What I'm doing wrong?
here the relevant code, the parameter I need to get in dataProvider is :namespace
and in dataProvider:14 Replies
Hi @_garubi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It seems you are trying to pass the
namespace
parameter through the meta
property in the <Refine>
component's resources
. However, the meta
property in the <Refine>
component's resources
is not directly passed to the data provider methods.
Instead, you should pass the namespace
parameter using the meta
property in the hooks that call the data provider methods. For example, if you are using the useList
hook, you can pass the namespace
like this:
Then, in your data provider, you can access the namespace
from the meta
object:
Remember to pass the meta
with the namespace
in all the hooks that call the data provider methods, such as useOne
, useCreate
, useUpdate
, etc.
For more information on how to use meta
to pass additional information to data provider methods, you can refer to the general concepts documentation (https://refine.dev/docs/api-reference/general-concepts/#meta).
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------General Concepts | refine
- refine core is fully independent of UI. So you can use core components and hooks without any UI dependency.
<@976939425848250478> kapa.ai is still learning and improving, please let us how it did by reacting below
national-gold•2y ago
Hey @_garubi
Parameters sent from data hooks such as
useList
are passed for the meta
parameter in the data provider.
https://refine.dev/docs/api-reference/core/hooks/data/useList/#metauseList | refine
useList is an extended version of TanStack Query's useQuery. It supports all the features of useQuery and adds some extra features.
absent-sapphireOP•2y ago
Thank you @yildirayunlu ! I'll give it a try in a few minutes..
@yildirayunlu tryed...but still no luck 😕
I'm sending the
meta
in useTable
this way:
and try to retrieve it in dataProvider, but I get nothing:
national-gold•2y ago
https://refine.dev/docs/api-reference/core/hooks/useTable/#meta
Here is a more detailed example. Also, do other parameters (resource, pagination) come here?
adverse-sapphire•2y ago
Hey @_garubi,
You need to send
meta
in refineCoreProps
prop. 🤞🏻absent-sapphireOP•2y ago
Thank you,
yes I started yesterday with it 😆 ... I re-done it now, without any luck...
I can confirm that pagination comes in and I got it working.
Here the code as it is now:
dataProvider:
btw How can I enable syntax highlighting in code bloks? (I'm pretty new to Discord)
adverse-sapphire•2y ago
If you use
useTable
from @refinedev/react-table
you need pass props like below:
Here is useTable
doc imported from @refinedev/react-table
: https://refine.dev/docs/packages/documentation/react-table/#metaabsent-sapphireOP•2y ago
Oh... now I understand!! 🤦♂️
It's working now!! thank you 🙂
Isn't there a way to send this "meda" from the rsource object in the app's
<Refine>
component?
I ask because, while sending parameter to dataProvider inside ute "useXX>" hook is ok for query related parameter, I'll need to send a "namespace" specific to the resource that will be prepended to every request for that resource.
So having it specified at resource level wuold make more sense.
It's a need related to haw the WordPress REST api I'm working on is structured, I explained in details here: https://discord.com/channels/837692625737613362/1093124784801468487/1093124784801468487adverse-sapphire•2y ago
Currently doesn't support this but it can be a very nice feature, can you create an issue for it?
You can also do this
namespace
setting on the dataProvider
side like below, so you have not to pass namespace
for all hooks.
absent-sapphireOP•2y ago
Sure, I'll go opening an issue later today 👌
Handling the namespace in the dataProvider solves my specific use case, with our specific WordPress installation, but you can't know what plugins (and thus namespaces) you'll find in other WP installation.
Thank you very much!
adverse-sapphire•2y ago
You're welcome 🤞🏻
Btw, you're right if it will be a package. However you can pass
namespaces
using dataProvider
arguments like below:
absent-sapphireOP•2y ago
that's brilliant! 👍