How to make mui list of images in react js?
March 10, 2024Hi Friends 👋,
Welcome To aGuideHub!
To make mui list of images in react js, You can add more ListItem
components with cardmedia
and typography
. It will make mui list of images in React JS.
Today, I am going to show you, How to make mui list of images in react js
Installation
Install the following packages mui list in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
Table of contents
- Install MUI and create a new React app.
- Import Material-UI list.
- Use the list Component.
Step 1: Install MUI and create a new React app.
First you have to install the React project. You should use create-react-app
command to create a new React project.
npx create-react-app my-app
cd my-app
npm start
Step 2: Import Material-UI list.
After installing MUI
, you have to import your React component. To do this, add the following line to the top of your component file.
import React from 'react';
import { List, ListItem, Card, CardMedia, Typography } from '@mui/material';
import mouse from './mouse.jpg';
import nature from './nature.jpg';
Step 3: Use the list Component.
Lists are a continuous group of text or images. They are composed of items containing primary and supplemental actions, which are represented by icons and text.
<List>
<ListItem>
<Card>
<CardMedia
component="img"
height="140"
src={mouse}
alt="Image 1"
/>
<Typography variant="body2">Mouse</Typography>
</Card>
</ListItem>
<ListItem>
<Card>
<CardMedia
component="img"
height="140"
src={nature}
alt="Image 2"
/>
<Typography variant="body2">Nature</Typography>
</Card>
</ListItem>
</List>
MUI material make mui list of images example.
The below code is an example, you need to import list
Component. Then, you have to use CardMedia
component in List
. Then it will make mui list of images in react js.
App.js
import React from 'react';
import { List, ListItem, Card, CardMedia, Typography } from '@mui/material';
import mouse from './mouse.jpg';
import nature from './nature.jpg';
function ListOfImages() {
return (
<List>
<ListItem>
<Card>
<CardMedia
component="img"
height="140"
src={mouse}
alt="Image 1"
/>
<Typography variant="body2">Mouse</Typography>
</Card>
</ListItem>
<ListItem>
<Card>
<CardMedia
component="img"
height="140"
src={nature}
alt="Image 2"
/>
<Typography variant="body2">Nature</Typography>
</Card>
</ListItem>
{/* Add more ListItems for additional images */}
</List>
);
}
export default ListOfImages;
In the above code example, I have used the @mui/material
component and make mui list of images in react js.
All the best 👍