-
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
added logic for add form #1804
base: master
Are you sure you want to change the base?
added logic for add form #1804
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.
Good job, but there is quite a bit of work to be done.
Now you can add a movie with empty information by putting empty spaces in each input:
https://gyazo.com/1e46cc4e36099e2b7fbe36b596d76d4e
src/components/NewMovie/NewMovie.tsx
Outdated
const [title, setTitle] = useState(''); | ||
const [description, setDescription] = useState(''); | ||
const [imgUrl, setImgUrl] = useState(''); | ||
const [imdbUrl, setImdbUrl] = useState(''); | ||
const [imdbId, setImdbId] = useState(''); |
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.
All this should be kept in one state.
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.
All this should be kept in one state.
You still have a state for each input, let's create one state for all of them. and one handler to update the state when onChange
event is triggered.
Your default state can looks like:
const deafultFormState = {
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
}
src/components/NewMovie/NewMovie.tsx
Outdated
setImdbId(''); | ||
}; | ||
|
||
const isDisabled = () => { |
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 isDisabled = () => { | |
const isAddButtonDisabled = () => { |
src/components/NewMovie/NewMovie.tsx
Outdated
return !(title && imgUrl && imdbUrl && imdbId); | ||
}; | ||
|
||
const submit = (): void => { |
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 submit = (): void => { | |
const handleSubmit = (): void => { |
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.
Good work 👍
But one moment still not fixed, check the comment
src/components/NewMovie/NewMovie.tsx
Outdated
const [title, setTitle] = useState(''); | ||
const [description, setDescription] = useState(''); | ||
const [imgUrl, setImgUrl] = useState(''); | ||
const [imdbUrl, setImdbUrl] = useState(''); | ||
const [imdbId, setImdbId] = useState(''); |
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.
All this should be kept in one state.
You still have a state for each input, let's create one state for all of them. and one handler to update the state when onChange
event is triggered.
Your default state can looks like:
const deafultFormState = {
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
}
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.
Nice work, but be careful with the naming.
src/components/NewMovie/NewMovie.tsx
Outdated
const [count, setCount] = useState(0); | ||
const [formValues, setFormValues] = useState(defaultFormValues); | ||
|
||
const formReset = () => { |
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 function name must begin with a verb.
const formReset = () => { | |
const resetForm = () => { |
src/components/NewMovie/NewMovie.tsx
Outdated
setCount((prevCount) => prevCount + 1); | ||
}; | ||
|
||
const handleChange = (name: string, newValue: 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.
The name should clearly describe what is happening in the handler:
const handleChange = (name: string, newValue: string) => { | |
const handleInputChange = (name: string, newValue: string) => { |
DEMO LINK