I'm doing a project where I need several recipe cards that will contain: title and ingredients. These cards should be expandable (the user will see the title and when clicking, the ingredients will be shown) and to facilitate, 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 another for the list of ingredients that will be rendered inside the card
Below are: the input object sample I used to test, how I thought about doing this object manipulation, and the error message displayed.
Input example:
const teste2 =[{
title:"Brigadeiro",
ingredients:["margarina","achocolatado","leite condensado"]
},{
title: "Pão assado",
ingredients:["pão","margarina"]
}]
As I thought of doing:
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 clue what to do? Is there a map()
method for objects?
Note:
I tried to separate the objects, creating one for the ingredient lists and rendering it inside the recipe cards, but the expandable={true}
property of the <CardText>
component stops working (ingredients always appear expanded). Note that in this test, I did not use objects.