component: provide the hint when there is no ingredients by merging multiple arrays into one
This commit is contained in:
parent
8eeb04f654
commit
b4fbdade6d
@ -5,13 +5,19 @@ import BurgerIngredient from './BurgerIngredient/BurgerIngredient';
|
||||
|
||||
const burger = (props) => {
|
||||
|
||||
const transformedIngredients = Object.keys(props.ingredients)
|
||||
let transformedIngredients = Object.keys(props.ingredients)
|
||||
.map(igKey => {
|
||||
return [...Array(props.ingredients[igKey])].map( (_, i) => {
|
||||
return <BurgerIngredient key={igKey + i} type={igKey} />;
|
||||
})
|
||||
});
|
||||
})
|
||||
.reduce((arr, el) => { // merge multiple arrays into one
|
||||
return arr.concat(el);
|
||||
}, []);
|
||||
|
||||
if (transformedIngredients.length === 0){
|
||||
transformedIngredients = <p>Please start adding ingredients</p>;
|
||||
}
|
||||
return (
|
||||
<div className={classes.Burger}>
|
||||
<BurgerIngredient type="bread-top" />
|
||||
|
@ -7,10 +7,10 @@ class BurgerBuilder extends Component {
|
||||
|
||||
state = {
|
||||
ingredients: {
|
||||
meat: 1,
|
||||
cheese: 1,
|
||||
salad: 2,
|
||||
bacon: 2,
|
||||
meat: 0,
|
||||
cheese: 0,
|
||||
salad: 0,
|
||||
bacon: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user