-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
add task solution #2401
base: master
Are you sure you want to change the base?
add task solution #2401
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.
src/App.tsx
Outdated
</div> | ||
<div className="sidebar"> | ||
<NewMovie /* onAdd={(movie) => {}} */ /> | ||
<NewMovie onAddMovie={handleAddMovie} /> |
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.
<NewMovie onAddMovie={handleAddMovie} /> | |
<NewMovie onAdd={handleAddMovie} /> |
setTouched(prev => ({ ...prev, [name]: true })); | ||
}; | ||
|
||
const handleChange = (name: string, value: string) => { |
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.
const handleChange = (name: string, value: string) => { | |
const handleChange = (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.
IT DOESN'T WORK THAT WAY(
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.
it should work, you can always ask for some help in the chat
but you also can leave your version, just specify types more precisely
const handleChange = (name: string, value: string) => { | |
const handleChange = (name: keyof Movie, value: string) => { |
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.
const handleChange = (name: string, value: string) => { | ||
setForm(prevForm => ({ | ||
...prevForm, | ||
[name]: 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.
[name]: value, | |
[event.target.name]: event.target.value, |
value="" | ||
onChange={() => {}} | ||
value={form.title} | ||
onChange={value => handleChange('title', 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.
onChange={value => handleChange('title', value)} | |
onChange={handleChange} |
You can create one event handler for all fields
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.
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.
please, feel free to tag me in the mate chat if you have some problems with this task
setTouched(prev => ({ ...prev, [name]: true })); | ||
}; | ||
|
||
const handleChange = (name: string, value: string) => { |
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.
it should work, you can always ask for some help in the chat
but you also can leave your version, just specify types more precisely
const handleChange = (name: string, value: string) => { | |
const handleChange = (name: keyof Movie, value: string) => { |
src/components/NewMovie/NewMovie.tsx
Outdated
const isFormValid = () => { | ||
const requiredFields = ['title', 'imgUrl', 'imdbUrl', 'imdbId']; | ||
return requiredFields.every(field => !!form[field as keyof MovieForm]); | ||
}; |
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.
const isFormValid = () => { | |
const requiredFields = ['title', 'imgUrl', 'imdbUrl', 'imdbId']; | |
return requiredFields.every(field => !!form[field as keyof MovieForm]); | |
}; | |
const isFormValid = () => { | |
const requiredFields = ['title', 'imgUrl', 'imdbUrl', 'imdbId']; | |
return requiredFields.every(field => !!form[field as keyof MovieForm].trim()); | |
}; |
to fix my prev comment
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.
It's still possible to add a new movie with only white spaces. Please use trim
on verification
setTouched(prev => ({ ...prev, [name]: true })); | ||
}; | ||
|
||
const handleChange = (name: string, value: string) => { |
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.
DEMO LINK