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 burger = (props) => {
|
||||||
|
|
||||||
const transformedIngredients = Object.keys(props.ingredients)
|
let transformedIngredients = Object.keys(props.ingredients)
|
||||||
.map(igKey => {
|
.map(igKey => {
|
||||||
return [...Array(props.ingredients[igKey])].map( (_, i) => {
|
return [...Array(props.ingredients[igKey])].map( (_, i) => {
|
||||||
return <BurgerIngredient key={igKey + i} type={igKey} />;
|
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 (
|
return (
|
||||||
<div className={classes.Burger}>
|
<div className={classes.Burger}>
|
||||||
<BurgerIngredient type="bread-top" />
|
<BurgerIngredient type="bread-top" />
|
||||||
|
@ -7,10 +7,10 @@ class BurgerBuilder extends Component {
|
|||||||
|
|
||||||
state = {
|
state = {
|
||||||
ingredients: {
|
ingredients: {
|
||||||
meat: 1,
|
meat: 0,
|
||||||
cheese: 1,
|
cheese: 0,
|
||||||
salad: 2,
|
salad: 0,
|
||||||
bacon: 2,
|
bacon: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user