-
Notifications
You must be signed in to change notification settings - Fork 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
Favour's PR #2
base: first
Are you sure you want to change the base?
Favour's PR #2
Conversation
src/components/Cart/Cart.js
Outdated
@@ -0,0 +1,17 @@ | |||
import React from "react"; | |||
import ItemList from "../Item-list/Item-list"; | |||
const cart = props => { |
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.
to support standards, name your components with a starting capital letter so we are able to differentiate between functions and components.
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.
refactor this to use map
instead of for
.. break the operation into 2 steps.. the first step should multiply each item price by its quantity and the second step will add up all the items in the array. this can be 2 separate functions chained together.
What i described above is functional programming 101
}; | ||
|
||
addToCart = (id) => { | ||
const inventoryIndex = this.state.inventory.findIndex(p => { |
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 refactor this operation to be a filter
and you return the output of the filter
Do not merge.. PR created for Code Review purposes