-
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
solution #2090
base: master
Are you sure you want to change the base?
solution #2090
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 , let's improve your code style!
src/components/NewMovie/NewMovie.tsx
Outdated
const [imdbUrl, setImdbUrl] = useState(''); | ||
const [imdbId, setImdbId] = useState(''); | ||
|
||
// const [hasReset, setHasReset] = useState(false); |
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.
Delete unnecessery comments
src/components/NewMovie/NewMovie.tsx
Outdated
|
||
// const [hasReset, setHasReset] = useState(false); | ||
|
||
const able = titleValue.trim() |
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.
I think you need to rename your variable, for better understanding
src/components/NewMovie/NewMovie.tsx
Outdated
onSubmit={event => { | ||
event.preventDefault(); | ||
submitAddMovie(); | ||
}} |
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.
Maybe you should move your "event.preventDefault();" to your function submitAddMovie.
And put here only link to your function
onSubmit={event => { | |
event.preventDefault(); | |
submitAddMovie(); | |
}} | |
onSubmit={submitAddMovie} |
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!🤗
<NewMovie /* onAdd={(movie) => {}} */ /> | ||
<NewMovie onAdd={(movie) => { | ||
setPrepMovies(currentMovies => [...currentMovies, movie]); | ||
}} |
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 create a separate handler for this
src/components/NewMovie/NewMovie.tsx
Outdated
const [description, setDescription] = useState(''); | ||
const [imgUrlValue, 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.
instead of creating a lot of states, use just one
const defaultMovie = {
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
};
const [count, setCount] = useState(0);
const [newMovie, setNewMovie] = useState(defaultMovie);
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!✨
src/components/NewMovie/NewMovie.tsx
Outdated
imdbUrl: newMovie.imdbUrl, | ||
imdbId: newMovie.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.
are you sure you need this function?
setCount((currentCount) => currentCount + 1); | ||
|
||
onAdd(movie); | ||
}; |
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.
you can write more simple
const submitAddMovie = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
onAdd(newMovie);
setNewMovie(defaultMovie);
setCount((currentCount) => currentCount + 1);
};
src/components/NewMovie/NewMovie.tsx
Outdated
onSubmit={event => { | ||
event.preventDefault(); | ||
submitAddMovie(); | ||
}} |
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.
and here write
onSubmit={submitAddMovie}
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.
Super! Thank you!✨
DEMO LINK