Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

destroy.tsx

14 lines477 Bytes

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