-
Notifications
You must be signed in to change notification settings - Fork 26
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
basket, remove item, price, total price #45
base: master
Are you sure you want to change the base?
Conversation
@@ -8,6 +8,9 @@ export default function (state = {}, action) { | |||
return { ...state, [id]: (state[id] || 0) + 1 }; | |||
case DECREMENT: | |||
return { ...state, [id]: (state[id] || 0) - 1 }; | |||
case REMOVE_ITEM: | |||
delete state[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.
это мутация данных предыдущего стейта, этого делать нельзя
import styles from './basket.module.css'; | ||
|
||
const Basket = ({ order, decrement, increment, restaurants, removeItem, handleBasket}) => { | ||
const dishes = [...restaurants].map(item => item.menu.map(item2 => item2)).flat(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.
это вычисление лучше мемоизировать
} | ||
}) | ||
} | ||
const totalPrice = selectedItems.reduce(( prev, cur ) => prev + cur.price*cur.qty, 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.
и в целом все эти вычисления можно вынести в mapStateToProps
No description provided.