Open dnhn opened 11 months ago
Result: ✅
AddEditBookDialog
into a BookForm
component, which accepts onSubmit
as a property.Then you can reuse it like this:
// AddBookDialog.tsx
<BookForm onSubmit={(values) => addBook(values)} />
// EditBookDialog.tsx
<BookForm initialValues={bookToEdit} onSubmit={(values) => editBook(values)} />
This way, you don't have to hard-code the async logic (create/edit requests) in the book form & can reuse it for other scenarios.
We can add something like this:
<Field label="Email" error={errors.email} {...} >
<input {...} />
</Field>
This will help make the form shorter, cleaner and more consistent.
https://dffe23-dn-5.vercel.app