-
Notifications
You must be signed in to change notification settings - Fork 0
Homework 2 #2
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?
Homework 2 #2
Conversation
} | ||
|
||
addToCart = (product) => { | ||
let self = this; |
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 could use arrow function instead of save context to additional variable
|
||
this.state.inCart.push(item); | ||
|
||
this.setState({ |
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.
such update could looks that way
this.setState({
inCart: [...this.state.incart, product]
})
let self = this; | ||
let item = this.state.products.find(function(item, index){ | ||
if (item.name == product.name) { | ||
self.state.products[index].inCart = 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.
if you have inCart in state and inCart in the object it seems like a duplication an additional overhead
Furthermore, it breaks one of principle "Single Source of Truth"
export class Admin extends Component { | ||
render() { | ||
|
||
return ( |
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.
please use prettier for code formatting
<h1>ADMIN PAGE</h1> | ||
<ul className="list-group"> | ||
{ | ||
this.props.products.map(product => { |
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 worth to move such logic to class method
{ | ||
this.props.products.map(product => { | ||
let inCart = product.inCart ? ( | ||
<div> |
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 worth to use React.Fragment there instead of extra div
<div className="row"> | ||
{ | ||
this.props.products.map(product => { | ||
let inCart = product.inCart ? ( |
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.
also, you could compare product inside inCart state property instead of check property of item
<h3 className="text-success">✓✓✓✓✓</h3> | ||
</div> | ||
) : ( | ||
<a href="#" className="btn btn-primary" onClick={() => this.props.addToCart(product)}>Buy</a> |
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.
please move onClick to class method
<div> | ||
User | ||
</div> | ||
<button onClick={this.props.changePageToCart}>Orders</button> |
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.
please use object destruction
@@ -0,0 +1,20 @@ | |||
{ | |||
"name": "youtube", |
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.
please move all youtube specific homework to another PR
No description provided.