Conversation
| } | ||
|
|
||
| addToCart = (product) => { | ||
| let self = this; |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
please move onClick to class method
| <div> | ||
| User | ||
| </div> | ||
| <button onClick={this.props.changePageToCart}>Orders</button> |
There was a problem hiding this comment.
please use object destruction
| @@ -0,0 +1,20 @@ | |||
| { | |||
| "name": "youtube", | |||
There was a problem hiding this comment.
please move all youtube specific homework to another PR
No description provided.