Download react-query/examples/react/react-router/src/routes/new.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 626 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/react-router/src/routes/new.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/react-router/src/routes/new.tsx
-
curl -L -o new.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/react-router/src/routes/new.tsx
626 Bytes
| import { redirect, ActionFunctionArgs } from 'react-router-dom' | |
| import { createContact } from '../contacts' | |
| import { QueryClient } from '@tanstack/react-query' | |
| import { ContactForm } from './edit' | |
| export const action = | |
| (queryClient: QueryClient) => | |
| async ({ request }: ActionFunctionArgs) => { | |
| const formData = await request.formData() | |
| const data = Object.fromEntries(formData) | |
| const contact = await createContact(data as any) | |
| queryClient.invalidateQueries({ queryKey: ['contacts', 'list'] }) | |
| return redirect(`/contacts/${contact.id}`) | |
| } | |
| export default function New() { | |
| return <ContactForm /> | |
| } | |