Skip to content
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 #2091

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

solution #2091

wants to merge 4 commits into from

Conversation

InnaSh23
Copy link

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

// reset();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

Comment on lines 55 to 60
useEffect(() => {
const isImgUrlValid = pattern.test(imgUrl);
const isImdbUrlValid = pattern.test(imdbUrl);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need in that useEffect. isFormValid can be just a common variable.

Suggested change
useEffect(() => {
const isImgUrlValid = pattern.test(imgUrl);
const isImdbUrlValid = pattern.test(imdbUrl);
setIsFormValid(!!title && isImgUrlValid && isImdbUrlValid && !!imdbId);
}, [title, imgUrl, imdbUrl, imdbId]);
const isFormValid = !!title && pattern.test(imgUrl) && pattern.test(imdbUrl) && !!imdbId

and then in JSX
<button ... disabled={isFormValid}>

It should work in the same way

Copy link

@maxim2310 maxim2310 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, but lets make some improvement

i try to add movie and fill in fields but button still disabled and haven't any error, looks strange
image

@InnaSh23 InnaSh23 requested a review from maxim2310 January 17, 2024 18:15
Copy link

@SanyaBratashchuk SanyaBratashchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] would be better to add error like 'url is not validinstead ofurl is requied` in such cases
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants