dnhn / df-fe-23

https://dffe23-dn-7.vercel.app
1 stars 0 forks source link

Assignment 5 #10

Open dnhn opened 11 months ago

dnhn commented 11 months ago

https://dffe23-dn-5.vercel.app

ngolapnguyen commented 10 months ago

Requirements

Result: ✅

Feedbacks

  1. I'd move these constants out of the component to avoid re-declaring them every render:
image
  1. You can extract the form logic out of the 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.

  1. Another good practice is to build a generic wrapper for form fields that share a similar layout:
image

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.

  1. ... (Please refer to my feedbacks in previous assignments)