React-map-multidimensional-matray
const { useState, Fragment } = React;
function Category({ category }) {
return (
<div className="category">
{
Object.entries(category).map(([categoryName, values]) => {
return (
<Fragment>
<h3>{categoryName}</h3>
<Fragment>
{values.map(({image, name}) => (
<Fragment>
<a href={`/categorypage`} className='sub-category'>
<img src={image} alt="" />
<p className='name'>{name}</p>
</a>
</Fragment>
))}
</Fragment>
</Fragment>
)
})
}
</div>
)
}
const App = () => {
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', }, ] }];
return (
<Fragment>
{categories.map((category) => (<Category category={category} />))}
</Fragment>)
}
ReactDOM.render(
<App />,
document.getElementById("root")
)
Relieved Rhinoceros