-
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
task done #2101
base: master
Are you sure you want to change the base?
task done #2101
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! Keep going!
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.
you can use object with type Movie and create only one state for all fields.
const InitialFieldsOfMovie: Movie = {
title: '',
description: '',
imgUrl: '',
imdbUrl: '',
imdbId: '',
};
// your code
const [fieldsOfMovie, setFieldsOfMovie] = React.useState(InitialFieldsOfMovie);
I think it's easier to use because you don't have to create a lot of states for each field, but your solution is also suitable (It is not necessary to change)
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.
We ask about this our teacher Misha and he said that it is not better.
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! Please check minor mistake and answer my question
src/components/NewMovie/NewMovie.tsx
Outdated
const [imdbUrl, setImdbUrl] = useState(''); | ||
const [imdbId, setImdbId] = useState(''); | ||
|
||
const isAbleToAdd = title && 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.
<form className="NewMovie" key={count}> | ||
<form | ||
className="NewMovie" | ||
key={count} |
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.
Why you need to add this key attribute? Why you need to reset "touched status"? Can you explain please?
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.
We use this key to rerender component with clear field
I use touched status to controll if field was used then clear and trying to switch to another field (I show error in this case)
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!
I added some comments that touch the clean code side.
Many thanks!
src/App.tsx
Outdated
import './App.scss'; | ||
import { MoviesList } from './components/MoviesList'; | ||
import { NewMovie } from './components/NewMovie'; | ||
import moviesFromServer from './api/movies.json'; | ||
|
||
export const App = () => { | ||
const [preparedMovies, setPreparedMovies] = useState(moviesFromServer); | ||
// const addNewMovie |
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.
remove this comment line
src/App.tsx
Outdated
<NewMovie onAdd={(movie) => { | ||
setPreparedMovies(currentList => [...currentList, 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 a handler for it ( not critical )
src/components/NewMovie/NewMovie.tsx
Outdated
// Increase the count after successful form submission | ||
// to reset touched status of all the `Field`s |
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.
Think you can remove it ( not critical )
setTitle(''); | ||
setDescription(''); | ||
setImgUrl(''); | ||
setImdbUrl(''); | ||
setImdbId(''); |
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 function reset for it
src/components/NewMovie/NewMovie.tsx
Outdated
<form | ||
className="NewMovie" | ||
key={count} | ||
onSubmit={addNewMovie} // (event) => {}, f(event) |
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.
remove comment line
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 job!
Approved.
Many thanks!
DEMO LINK