absent-sapphire
absent-sapphire7mo ago

Is it possible to access meta values passed into <DeleteButton meta={...} /> on the backend?

I am using the delete button provided by @refinedev/antd. Looking at the docs, I see meta property where I can add some additional data. How do I access the values in meta when making the delete request?
6 Replies
kapa.ai
kapa.ai7mo ago
Hi @Syn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The meta property in the DeleteButton component is used to pass additional parameters to the useDelete hook. However, the provided extracts do not contain specific information on how to access these meta values when making the delete request. The DeleteButton component in @refinedev/antd uses the useDelete hook directly. When you click the button, it triggers the useDelete method and the record gets deleted. The mutate function from useDelete is passed to the onConfirm prop of the Popconfirm component, which means it invokes dataProvider.delete upon confirmation of a delete pop up. Here is the code snippet showing how useDelete is used in DeleteButton:
const { mutate, isLoading, variables } = useDelete();

return (
<Popconfirm
// ...
onConfirm={(): void => {
if ((recordItemId ?? id) && resource?.name) {
mutate(
{
id: recordItemId ?? id ?? "",
resource: resource?.name,
mutationMode,
successNotification,
errorNotification,
meta: pickNotDeprecated(meta, metaData),
metaData: pickNotDeprecated(meta, metaData),
dataProviderName,
invalidates,
},
{
onSuccess: (value) => {
onSuccess && onSuccess(value);
},
},
);
}
}}
// ...
</Popconfirm>
);
const { mutate, isLoading, variables } = useDelete();

return (
<Popconfirm
// ...
onConfirm={(): void => {
if ((recordItemId ?? id) && resource?.name) {
mutate(
{
id: recordItemId ?? id ?? "",
resource: resource?.name,
mutationMode,
successNotification,
errorNotification,
meta: pickNotDeprecated(meta, metaData),
metaData: pickNotDeprecated(meta, metaData),
dataProviderName,
invalidates,
},
{
onSuccess: (value) => {
onSuccess && onSuccess(value);
},
},
);
}
}}
// ...
</Popconfirm>
);
As you can see, the meta values are passed to the mutate function. However, the exact way to access these meta values during the delete request is not specified in the provided extracts. For more detailed information, you may want to refer to the official refine documentation (https://refine.dev/docs). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@183085423604662273> kapa.ai is still learning and improving, please let us know how it did by reacting below
absent-sapphire
absent-sapphire7mo ago
@kapa.ai this is an example DELETE endpoint in nextjs:
export async function DELETE(_: NextRequest, { params }: { params: { id: string } }) {
console.log('deleting at id:', params.id)
return NextResponse.json({ message: 'delete request hit' }, { status: 200 })
}
export async function DELETE(_: NextRequest, { params }: { params: { id: string } }) {
console.log('deleting at id:', params.id)
return NextResponse.json({ message: 'delete request hit' }, { status: 200 })
}
On my delete button, i have this:
<DeleteButton confirmTitle='Delete Tooltip?' hideText recordItemId={id} meta={{ category, subcategory }} />
<DeleteButton confirmTitle='Delete Tooltip?' hideText recordItemId={id} meta={{ category, subcategory }} />
How do I access the meta values within my delete request?
kapa.ai
kapa.ai7mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry, but the provided extracts do not contain specific information on how to access meta values within a delete request in Next.js using the DeleteButton component from @refinedev/antd. The meta property in the DeleteButton component is used to pass additional parameters to the useDelete hook. However, how these meta values are passed to the server-side and how to access them in your Next.js API route is not specified in the provided extracts. For more detailed information, you may want to refer to the official refine documentation (https://refine.dev/docs) or Next.js documentation on API Routes (https://nextjs.org/docs/api-routes/introduction). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@183085423604662273> kapa.ai is still learning and improving, please let us know how it did by reacting below
like-gold
like-gold7mo ago
Hello @Syn, meta property is passed to your data provider's deleteOne method. You can access it from there. If you are using data provider package, you can swizzle it and modify as you need. https://refine.dev/docs/guides-concepts/development/#using-swizzle
Development | refine
Refine offers improved developer experience by providing a set of tools to help you develop your application. These tools will help you from creating a new project to developing, customizing and debugging your application. This guide will introduce you to these tools and how to use them.