-
Notifications
You must be signed in to change notification settings - Fork 35
React cinema #15
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
base: master
Are you sure you want to change the base?
React cinema #15
Conversation
| render(){ | ||
| let check={fav_on:false}; | ||
|
|
||
| this.props.favList.find(movie => movie.imdbID==this.props.id)? check={fav_on:true}: |
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.
Ternary return a value. As a result it would better to rewrite above as const check=this.props.favList.find(movie => movie.imdbID==this.props.id)? {fav_on:true}:{fav_on:false}
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.
Better still, since we use check in cx, we can simplify above to const favOn=this.props.favList.find(movie => movie.imdbID==this.props.id); and then use it as
const classes=cx('material-icons md-24',{fav_on: favOn}); in cx
|
|
||
| receiveFavClick(id){ | ||
|
|
||
| if(this.state.favList.filter(movie => movie.imdbID==id).length == 0){ |
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.
It would be cleaner to calculate to generate a favList array in if/else, then you can set it in state and localStorage after and you would not need to duplicate code. Also, since favList would be precomputed we would not need to use a callback when setting it in localStorage
|
|
||
| receiveDeleteClick(id){ | ||
| this.setState({ | ||
| favList: this.state.favList.filter(movie => movie.imdbID !== 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.
it would be better to create a favList array first then set it both in state and localStorage without using the callback
| } | ||
|
|
||
| render(){ | ||
| const storageString=localStorage.getItem('favList') |
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.
It would better to use favList from state rather than getting it from localStorage. favList in state should have same items.
|
Nice work. A few bits could be a slightly more concise or tidied up but very nice work overall |
No description provided.