mirror of
https://github.com/vercel/next-learn.git
synced 2026-07-08 06:28:41 +00:00
Use bind instead of hidden field (#311)
* Use bind instead of hidden field * Update actions.ts
This commit is contained in:
committed by
GitHub
parent
8543a0d55f
commit
5a65b98034
@@ -26,9 +26,10 @@ export function UpdateInvoice({ id }: { id: string }) {
|
||||
}
|
||||
|
||||
export function DeleteInvoice({ id }: { id: string }) {
|
||||
const deleteInvoiceWithId = deleteInvoice.bind(null, id);
|
||||
|
||||
return (
|
||||
<form action={deleteInvoice}>
|
||||
<input type="hidden" name="id" value={id} />
|
||||
<form action={deleteInvoiceWithId}>
|
||||
<button className="rounded-md border p-2 hover:bg-gray-100">
|
||||
<span className="sr-only">Delete</span>
|
||||
<TrashIcon className="w-5" />
|
||||
|
||||
@@ -20,13 +20,12 @@ export default function EditInvoiceForm({
|
||||
customers: CustomerField[];
|
||||
}) {
|
||||
const initialState = { message: null, errors: {} };
|
||||
const [state, dispatch] = useFormState(updateInvoice, initialState);
|
||||
const updateInvoiceWithId = updateInvoice.bind(null, invoice.id);
|
||||
const [state, dispatch] = useFormState(updateInvoiceWithId, initialState);
|
||||
|
||||
return (
|
||||
<form action={dispatch}>
|
||||
<div className="rounded-md bg-gray-50 p-4 md:p-6">
|
||||
{/* Invoice ID */}
|
||||
<input type="hidden" name="id" value={invoice.id} />
|
||||
{/* Customer Name */}
|
||||
<div className="mb-4">
|
||||
<label htmlFor="customer" className="mb-2 block text-sm font-medium">
|
||||
|
||||
Reference in New Issue
Block a user