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

movies-list-add-form #2085

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

Conversation

Q1W2E3R4T5Y6U7I8a
Copy link

Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

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

something wrong with your link, feel free to ask for some help with that in the chat

Comment on lines 7 to 11
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [imgUrl, setImgUrl] = useState('');
const [imdbUrl, setImdbUrl] = useState('');
const [imdbId, setImdbId] = useState('');

Choose a reason for hiding this comment

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

we can combine it in one useState

const [newMovie, setNewMovie] = useState({
  title: '',
  ...
})

now we can also create only one handle function for all fields

const handleChange = (e: ...) => {
  const {name, value} = e.target;
  setMovie((prevMovie) => ({...prevMovie, [name]: value}))
}

don't forget to specify name attr to input in TextField

Copy link

@nazarmatsevych nazarmatsevych left a comment

Choose a reason for hiding this comment

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

demo link doesn't work, try to rerun "npm run deploy" command or ask for help in fe_chat

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

form works strange, errors appear in different places and dont added new film after submit
https://www.loom.com/share/ef26224b8df14f3a8dcbd0ec67dbb511

Comment on lines +9 to +19

export const NewMovie: React.FC<Props> = ({ onAdd }) => {
const [count, setCount] = useState(0);

const [newMovie, setNewMovie] = useState({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});

Choose a reason for hiding this comment

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

move an initial state to a variable

Suggested change
export const NewMovie: React.FC<Props> = ({ onAdd }) => {
const [count, setCount] = useState(0);
const [newMovie, setNewMovie] = useState({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});
const initialMovieState = {
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
}
export const NewMovie: React.FC<Props> = ({ onAdd }) => {
const [count, setCount] = useState(0);
const [newMovie, setNewMovie] = useState(initialMovieState);

Comment on lines +60 to +66
setNewMovie({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});

Choose a reason for hiding this comment

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

Suggested change
setNewMovie({
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
});
setNewMovie(initialMovieState);

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.

5 participants