-
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
add solution #2115
base: master
Are you sure you want to change the base?
add solution #2115
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!
I have added comments for improvement in your application.
Many thanks!
src/components/NewMovie/NewMovie.tsx
Outdated
const isFieldsFill = title.trim() !== '' | ||
&& imgUrl.trim() !== '' | ||
&& imdbUrl.trim() !== '' | ||
&& imdbId.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.
const isFieldsFill = title.trim() !== '' | |
&& imgUrl.trim() !== '' | |
&& imdbUrl.trim() !== '' | |
&& imdbId.trim() !== ''; | |
const isFieldsFill = !title.trim() | |
&& !imgUrl.trim() | |
&& !imdbUrl.trim() | |
&& !imdbId.trim(); |
Try rewriting for the best readability!
src/components/NewMovie/NewMovie.tsx
Outdated
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.
Try to think how you can use one state for all form data
src/App.tsx
Outdated
|
||
export const App = () => { | ||
const [movies, setMovies] = useState(moviesFromServer); | ||
const [newMovieId, setNewMovieId] = useState('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.
what does 's' ? Fix naming or remove this value
src/App.tsx
Outdated
const [newMovieId, setNewMovieId] = useState('s'); | ||
const addMovie = (movie: Movie) => { | ||
setMovies(existingMovies => [...existingMovies, movie]); | ||
setNewMovieId(Math.random().toString(16).slice(2)); |
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 create a helper function that return your generated id
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.
Approved with small comments!
Thanks.
// 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.
Remove this comment line*
import './App.scss'; | ||
import { MoviesList } from './components/MoviesList'; | ||
import { NewMovie } from './components/NewMovie'; | ||
import moviesFromServer from './api/movies.json'; | ||
import { Movie } from './types/Movie'; | ||
|
||
const getNewId = () => Math.random().toString(16).slice(2); |
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 move it from component file
DEMO LINK