Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
InnaSh23 committed Jan 15, 2024
1 parent c107ff3 commit be2caa8
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/components/NewMovie/NewMovie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export const NewMovie: React.FC<Props> = ({ onAdd }) => {
const handleInputChange = (
setter: React.Dispatch<React.SetStateAction<string>>, value: string,
) => {
const isValid = !!title && pattern.test(imgUrl)
&& pattern.test(imdbUrl) && !!imdbId;

setter(value);
setIsFormValid(isValid);
};

const handleSubmit = (event: React.FormEvent) => {
Expand All @@ -48,17 +52,8 @@ export const NewMovie: React.FC<Props> = ({ onAdd }) => {

onAdd(newMovie);
setCount(count + 1);

// reset();
};

useEffect(() => {
const isImgUrlValid = pattern.test(imgUrl);
const isImdbUrlValid = pattern.test(imdbUrl);

setIsFormValid(!!title && isImgUrlValid && isImdbUrlValid && !!imdbId);
}, [title, imgUrl, imdbUrl, imdbId]);

useEffect(() => {
if (count > 0) {
reset();
Expand Down

0 comments on commit be2caa8

Please sign in to comment.