Strangely, I have <Avatar>
that works with single object parse using .map
<Flex>
<div></div>
{studentsjson.map((thr) => (
<Avatar color="red" key={thr.id} component={Link} to="/complete">
{thr.Name}
</Avatar>
))}
</Flex>
However, below does not work
{
teacher.map((thr) =>
thr.students.map((stu) => {
<Avatar color="red" key={stu.id} component={Link} to="/complete">
{stu.studentName}
</Avatar>;
})
)
}
3
Answers
Following place is where you are making mistake.
add a return statement or remove
{
curly braces.In the second block of code, the problem is that you are only looping through
students
creating<Avatar/>
s but nothing is returned, you either have to useimplicit return :
or explicit return :
to return an non empty array.
As others have mentioned, the callback argument of the nested
.map
returns nothing. Hence, nothing can be expected to render. This can be fixed removing the curly braces to perform an "implicit return".I have a feeling you’ll want to use
Array.prototype.flatMap
as well; e.g.