How to have nested loops with map in JSX?

前端 未结 3 1675
北恋
北恋 2021-01-01 11:11

I can\'t achieve to have two nested map:

render() {
    return (
      
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 11:41

    I struggled for a while to get my nested map function to work only to discover that what you return is critical. Make sure you are returning the second map itself and not just the final expected output:

    let { categories } = data;
    
    categories = categories.map(category =>
        category.subcategories.map((subcategory, i) => 

    {subcategory.name}

    ) ); return (
    {categories}
    );

提交回复
热议问题