1
I’m doing a project where I need several recipe cards that will contain: title and ingredients. These cards must be expandable (The user will see the title and when clicking, the ingredients will be shown) and for ease, I am using the Ui Material.
As I do not know the amount (the application will be dynamic), I would like to use map()
and I noticed that I will need two map()
: One for the cards and one for the list of ingredients that will be rendered inside the card.
Below are: the example of input object I used to test, how I thought to handle this object and the error message displayed.
Input example:
const teste2 =[{
title:"Brigadeiro",
ingredients:["margarina","achocolatado","leite condensado"]
},{
title: "Pão assado",
ingredients:["pão","margarina"]
}]
Like I thought I would:
const Recipes = (props) =>{
let recipesList = props.objects.map((object, index)=>{
let ingrList = object.ingredients.map((ingred,index)=>(
<CardText expandable={true}>
{ingred}
</CardText>
))
return(
<Card>
<CardHeader
title={object.title}
actAsExpander={true}
showExpandableButton={true}
/>
<CardText>
{ingrList}
</CardText>
</Card>
)})
}
Error:
Recipes(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
Evaluating index.js
Would anyone have a hint of what to do? Is there any method map()
for objects?
Observing:
I tried to separate the objects further, creating one for the ingredient lists and rendering it within the recipe cards, but the property expandable={true}
of the component <CardText>
crashes (the ingredients are always expanded). It is worth noting that, in this test, I did not use objects.
Your code sounds good, where are you using later that
Recipes
? Where is the main component and therender()
?– Sergio