I was wondering if there is a way, to destructe and use an array method at the same time? If yes, is it useful to use it, or would it decrease the code readabilty so much, that it's not worth it?
My current code is this:
const { props: { title, ingredients: ing } } = this;
const ingredients = ing.map(
(ing, index) => <li key={index}>{ing}</li>
);
But I'm trying to find a shorter way like this:
const { props: { title, ingredients: ingredients.map(
(ing, index) => <li key={index}>{ing}</li>
); } } = this;
This code doesn't work though. Any tips would be much appreciated! :)
const { title, ingredients } = this.props
then maybe name the next variableconst ingredientElements
. Of course, it's your code, but someone might have to read and understand it later, including your future self 😉 – Nina