File size: 477 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import { ActionFunctionArgs, redirect } from 'react-router-dom'
import { deleteContact } from '../contacts'
import { QueryClient } from '@tanstack/react-query'
export const action =
(queryClient: QueryClient) =>
async ({ params }: ActionFunctionArgs) => {
if (!params.contactId) {
throw new Error('No contact ID provided')
}
await deleteContact(params.contactId)
queryClient.invalidateQueries({ queryKey: ['contacts'] })
return redirect('/')
}
|