how to map thorugh a multidimantional array in react?. this method is working fine with a simple but the output is not showing with this type of array. there is no error message as well.
two 'category' divs appear in the page but they are empty the content is not showing.my desired out come is:
<div className="category">
<h3>Gadgets</h3>
<a href={`/categorypage`} className='sub-category'>
<img src='/assets/images/iphone.png' alt="" />
<p className='name'>iphone</p>
</a>
<a href={`/categorypage`} className='sub-category'>
<img src='/assets/images/samsung.jpg' alt="" />
<p className='name'>samsung</p>
</a>
</div>
<div className="category">
<h3>Books</h3>
<a href={`/categorypage`} className='sub-category'>
<img src='/assets/images/book-1.jpg' alt="" />
<p className='name'>Fiction</p>
</a>
<a href={`/categorypage`} className='sub-category'>
<img src='/assets/images/book-2.jpg' alt="" />
<p className='name'>education</p>
</a>
</div>
array:
const Categories = [
{
'Gadgets': [
{
'name': 'iphone',
'image': '/assets/images/iphone.png',
},
{
'name': 'samsung',
'image': '/assets/images/samsung.jpg',
},
]
},
{
'Books': [
{
'name': 'Fiction',
'image': '/assets/images/book-1.jpg',
},
{
'name': 'education',
'image': '/assets/images/book-2.jpg',
},
]
}
]
export default Categories
category.js:
function Category({ category }) {
return (
<div className="category">
<h3>{category.category}</h3>
<a href={`/categorypage`} className='sub-category'>
<img src={category.image} alt="" />
<p className='name'>{category.name}</p>
</a>
</div>
)
}
app.js:
{Categories.map((category, i) => (
<Category category={category} />
))}