-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #2673
base: master
Are you sure you want to change the base?
Solution #2673
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this pull request! 😊 While you've made great progress, there are a few critical issues that need to be addressed to ensure the functionality and core requirements are fully met:
-
Form Submission Handling: The
onSubmit
function in theNewMovie
component needs to explicitly receive theevent
parameter to prevent default form submission behavior properly. This is crucial for the form to work as expected. -
State Update Logic: The
onAdd
prop in theNewMovie
component directly usessetMovies
. It's important to update the state based on the previous state to avoid potential issues. Use a function likesetMovies(prevMovies => [...prevMovies, newMovie])
to ensure the movie list updates correctly. -
Validation on Blur: Implement validation logic for required fields on
onBlur
to provide immediate feedback to users when fields are left empty. -
Form Reset and Error Handling: Ensure that errors are cleared when the form is reset. This will improve the user experience by providing a clean slate after each submission.
-
Advanced Validation: Consider implementing the optional advanced validation for URL fields to enhance the robustness of your form.
Once these issues are addressed, your code will be in great shape! Keep up the fantastic work, and don't hesitate to reach out if you need any help. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/App.tsx
Outdated
</div> | ||
<div className="sidebar"> | ||
<NewMovie /* onAdd={(movie) => {}} */ /> | ||
<NewMovie onAdd={setMovies} movies={movies} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onAdd
prop is directly using setMovies
. Ensure that the NewMovie
component correctly handles adding a new movie to the existing list. Typically, setMovies
should be used with a function that takes the previous state as an argument, like setMovies(prevMovies => [...prevMovies, newMovie])
, to avoid potential state update issues.
src/components/NewMovie/NewMovie.tsx
Outdated
<form | ||
className="NewMovie" | ||
key={count} | ||
onSubmit={() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onSubmit
function should explicitly receive the event
parameter to avoid potential issues. Change the function signature to onSubmit={(event) => { ... }}
.
src/components/NewMovie/NewMovie.tsx
Outdated
value="" | ||
onChange={() => {}} | ||
value={title} | ||
onChange={setTitle} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onChange
handler should properly handle the event object. Typically, it should be onChange={(e) => setTitle(e.target.value)}
to correctly update the state with the input value.
src/components/NewMovie/NewMovie.tsx
Outdated
name="description" | ||
label="Description" | ||
value={description} | ||
onChange={setDescription} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onChange
handler should properly handle the event object. Typically, it should be onChange={(e) => setDescription(e.target.value)}
to correctly update the state with the input value.
src/components/NewMovie/NewMovie.tsx
Outdated
name="imgUrl" | ||
label="Image URL" | ||
value={imageUrl} | ||
onChange={setImageUrl} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onChange
handler should properly handle the event object. Typically, it should be onChange={(e) => setImageUrl(e.target.value)}
to correctly update the state with the input value.
src/components/NewMovie/NewMovie.tsx
Outdated
name="imdbUrl" | ||
label="Imdb URL" | ||
value={imdbUrl} | ||
onChange={setImdbUrl} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onChange
handler should properly handle the event object. Typically, it should be onChange={(e) => setImdbUrl(e.target.value)}
to correctly update the state with the input value.
src/components/NewMovie/NewMovie.tsx
Outdated
name="imdbId" | ||
label="Imdb ID" | ||
value={imdbId} | ||
onChange={setImdbId} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onChange
handler should properly handle the event object. Typically, it should be onChange={(e) => setImdbId(e.target.value)}
to correctly update the state with the input value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on making several improvements to your code! 🎉 Your implementation of the App.tsx
and NewMovie
components shows a solid understanding of React fundamentals, especially in handling form submissions and state updates. Here are some key points to focus on for further enhancement:
-
Form Submission Handling: You've correctly implemented the
onSubmit
function to prevent default behavior, which is essential for custom form handling. -
State Update Logic: The use of
setMovies(prevMovies => [...prevMovies, newMovie])
ensures that your movie list updates correctly, maintaining the integrity of your state. -
Validation on Blur: Implementing validation logic on
onBlur
for required fields is crucial for providing immediate user feedback. This will enhance the user experience by alerting users to any missing information before form submission. -
Form Reset and Error Handling: Your approach to resetting the form and clearing errors is well-executed, ensuring a smooth user experience after each submission.
-
Advanced Validation: While optional, consider adding advanced validation for URL fields to further improve form robustness.
Remember, addressing these issues will not only meet the task requirements but also improve the overall quality of your code. Keep up the great work, and continue to learn from these experiences to refine your coding skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
</div> | ||
<div className="sidebar"> | ||
<NewMovie /* onAdd={(movie) => {}} */ /> | ||
<NewMovie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the NewMovie
component is properly handling form submissions and validations. Refer to the previous review comments regarding form submission handling, state update logic, and validation.
<form | ||
className="NewMovie" | ||
key={count} | ||
onSubmit={event => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onSubmit
function correctly receives the event
parameter and calls preventDefault()
, which is a good practice to prevent the default form submission behavior.
imdbId: imdbId, | ||
}; | ||
|
||
if (!Object.values(newMovie).some(value => !value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider implementing validation logic for required fields on onBlur
to provide immediate feedback to users when fields are left empty. This will improve the user experience by ensuring that users are aware of any missing information before attempting to submit the form.
|
||
if (!Object.values(newMovie).some(value => !value)) { | ||
onAdd(newMovie); | ||
handleResetForm(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that errors are cleared when the form is reset. This will improve the user experience by providing a clean slate after each submission.
name="imgUrl" | ||
label="Image URL" | ||
value={imageUrl} | ||
onChange={(newValue: string) => setImageUrl(newValue)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider implementing advanced validation for the imgUrl
field to ensure that the input is a valid URL. This will enhance the robustness of your form.
name="imdbUrl" | ||
label="Imdb URL" | ||
value={imdbUrl} | ||
onChange={(newValue: string) => setImdbUrl(newValue)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider implementing advanced validation for the imdbUrl
field to ensure that the input is a valid URL. This will enhance the robustness of your form.
DEMO LINK