Open In App

React MUI Pagination Navigation

React MUI is a UI library that provides fully-loaded components, bringing our own design system to our production-ready components. MUI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based on top of Material Design by Google.

In this article, we’ll be discussing React MUI Pagination Navigation. The Pagination component allows the user to select a specific page from a range available of pages.



Pagination Navigation Variants:

 



Syntax:

<Pagination count={...} />

Creating React Project:

Step 1: To create a react app, install react modules through the npm command.

npm create-react-app project name

Step 2: After creating your react project, move into the folder to perform different operations.

cd project name

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install @mui/material @emotion/react @emotion/styled

Project Structure:

 

Step to Run Application: Open the terminal and type the following command.

npm start

Example 1: Below example demonstrates the React MUI outlined pagination navigation.




import { Pagination } from "@mui/material";
import * as React from "react";
  
function App() {
    return (
        <center>
            <div>
                <h1 style={{ color: "green" }}>
                    GeeksforGeeks
                </h1>
                <h2>React MUI Pagination navigation</h2>
            </div>
            <div style={{ width: "50%" }}>
                <Pagination count={20} variant="outlined" 
                    color="standard" />
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Example 2: Below example demonstrates the React MUI controlled pagination navigation.




import { Pagination } from "@mui/material";
import * as React from "react";
  
function App() {
  
    const [page, setPage] = React.useState(1);
    const handlePageChange = (e, value) => {
        setPage(value);
    };
  
    return (
        <center>
            <div>
                <h1 style={{ color: "green" }}>
                    GeeksforGeeks
                </h1>
                <h2>React MUI Pagination navigation</h2>
            </div>
            <div style={{
                display: 'flex'
                flexDirection: 'column-reverse',
                justifyContent: 'center'
                alignItems: 'center'
            }}>
                <h3>You are at: {page} page</h3>
                <Pagination count={20} color="secondary"
                    onChange={handlePageChange} />
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Reference: https://mui.com/material-ui/react-pagination/


Article Tags :