Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sphariab
Copy link

@sphariab sphariab commented Dec 9, 2021

No description provided.

@@ -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];
Copy link
Owner

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);
Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и в целом все эти вычисления можно вынести в mapStateToProps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants