Build a COMPLETE React Admin Dashboard App
If you are looking to build an admin dashboard app using React, Material UI, Data Grid, and support for both light and dark mode, you’re in the right place. In this tutorial, we will walk you through the process of creating a fully functional admin dashboard app with all these features.
Prerequisites
Before we begin, make sure you have a basic understanding of React and JavaScript. Familiarity with Material UI and its components will also be beneficial.
Setting Up Your Project
Start by creating a new React project. You can use Create React App or any other tool of your choice.
Open your project in your preferred code editor and install the required dependencies:
npm install @material-ui/core @material-ui/icons @mui/x-data-grid
Creating the Dashboard Layout
Now, let’s start by creating the dashboard layout. We will define the basic structure of our app using HTML and CSS. Feel free to style the app as per your preferences.
Here, we will use Material UI components to build the layout. Material UI provides pre-defined components that follow the Material Design guidelines, making it easy to create a visually appealing dashboard.
<div className="dashboard">
<AppBar position="static">
<Toolbar>
<Typography variant="h6">Admin Dashboard</Typography>
</Toolbar>
</AppBar>
<div className="content">
<Sidebar />
<main>
<DashboardCards />
<DataGrid />
</main>
</div>
</div>
Adding Data Grid
The Data Grid component allows you to display and manipulate large amounts of data in a tabular format. Install the required dependencies for Data Grid:
npm install @mui/x-data-grid
Create a new component called DataGrid.js and import the necessary dependencies:
import { DataGrid } from '@mui/x-data-grid';
const columns = [
{ field: 'id', headerName: 'ID', width: 90 },
{ field: 'firstName', headerName: 'First name', width: 150 },
{ field: 'lastName', headerName: 'Last name', width: 150 },
{ field: 'age', headerName: 'Age', type: 'number', width: 90 },
];
const rows = [
{ id: 1, lastName: 'Snow', firstName: 'Jon', age: 35 },
{ id: 2, lastName: 'Lannister', firstName: 'Cersei', age: 42 },
{ id: 3, lastName: 'Lannister', firstName: 'Jaime', age: 45 },
{ id: 4, lastName: 'Stark', firstName: 'Arya', age: 16 },
{ id: 5, lastName: 'Targaryen', firstName: 'Daenerys', age: null },
{ id: 6, lastName: 'Melisandre', firstName: null, age: 150 },
{ id: 7, lastName: 'Clifford', firstName: 'Ferrara', age: 44 },
{ id: 8, lastName: 'Frances', firstName: 'Rossini', age: 36 },
{ id: 9, lastName: 'Roxie', firstName: 'Harvey', age: 65 },
];
function DataGrid() {
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid rows={rows} columns={columns} pageSize={5} checkboxSelection />
</div>
);
}
export default DataGrid;
Adding Light & Dark Mode
To support both light and dark mode, we will use Material UI’s ThemeProvider component. This component allows us to define our custom themes and switch between them based on our users’ preferences.
Import the necessary dependencies:
import { createTheme, ThemeProvider } from '@material-ui/core/styles';
const lightTheme = createTheme({
palette: {
type: 'light',
},
});
const darkTheme = createTheme({
palette: {
type: 'dark',
},
});
function App() {
const [isDarkMode, setIsDarkMode] = useState(false);
const theme = isDarkMode ? darkTheme : lightTheme;
const toggleTheme = () => {
setIsDarkMode(!isDarkMode);
};
return (
<ThemeProvider theme={theme}>
<div className="App">
<button onClick={toggleTheme}>Toggle Theme</button>
<Dashboard />
</div>
</ThemeProvider>
);
}
export default App;
Conclusion
Congratulations! You have successfully built a complete React admin dashboard app with support for Material UI, Data Grid, and both light and dark mode. You can now customize this app further to meet your specific requirements and add additional features as needed.
Remember to regularly update your dependencies and stay up-to-date with new releases of React, Material UI, and other libraries you are using in your project.
Hey all! It seems that react-pro-sidebar got updated recently so at 5:41 instead of installing "react-pro-sidebar" please install "react-pro-sidebar@0.7.1" or else it'll break!
Questions and Discussions about this project can be asked here in discord: https://discord.gg/2FfPeEk2mX
Is tailwind css being used here?
I added a few more components to my dashboard which meant that i had to scroll down, but when i was scrolling down, i noticed sidebar moved along as well. I tried to make its position fixed but it totally messed up my layout. I tried some other tricks on the internet but none of them worked. can you please tell me how i'd achieve that?
When I run the npm packages install command, I'm getting loads of vulnerability warnings, 25 vulnerabilities (2 moderate, 23 high). Is this something to be concerned about, and is this an extra step in this tutorial which has been skipped, i.e how to deal with these warnings? Many people who watched this awesome tutorial must of contended with this, right? I'm a newbee to react, and have some fairly solid HTML, CSS, JavaScript and PHP experience. However, dealing with all these package errors seems very concerning, is this always the case? I just want to start learning React and writing some code!
The below is what I'm running.
npm i @mui/material @emotion/react @emotion/styled @mui/x-data-grid @mui/icons-material react-router-dom@6 react-pro-sidebar@0.7.1 formik yup @fullcalendar/core @fullcalendar/daygrid @fullcalendar/timegrid @fullcalendar/list @nivo/core @nivo/pie @nivo/line @nivo/bar @nivo/geo
Hello Sir EdRoh
Thanks for your Great tutorial
I have a question, I want to have the ability to receive information from the Api and send information to the Api in such a project, do you have a video about this? So that I can learn this process and implement it.
Can you guide me in React, what topic should I read for this?
Thank you, best regards
Hey Guys, I was doing step by step the tutorial until a got to 1:04:37 and I got completely lost, Sidebar.jsx is completely different!, where do I need to jump in the timeline to understand the Sidebar.jsx ? Thanks in advance!
you gotta love the missing parts here and there…
Good morning, thanks for the wonderful video, I wanted to ask you how can I now connect the data from the site to the dashboard? for example, is it possible that anyone who registers on my site will be automatically included in the dashboard? Or for those who buy something? or is it still all manual entry? Thanks for the reply
When I started building the Teams page, I noticed the route (due to clicking on Teams from sidebar) was not working. I found 'You need to enable Javascript' in Network tab of developers tool; anyone else get this error?
Bro, i tried using your code, it gives a ton of errors
ERROR in ./src/scenes/global/Sidebar.jsx 89:35-45
export 'default' (imported as 'ProSidebar') was not found in 'react-pro-sidebar' (possible exports: Menu, MenuItem, ProSidebar, SidebarContent, SidebarFooter, SidebarHeader, SubMenu)
Bro i have a problem in it comes nom errr when i in stall form npm i muiaterial can u tell me what is the mistake i was get in to
You are a GENIUS! Thanks for the template!
Hi Ed, Make a video on how to connect this project's data to a private database on Github! Thanks!
anyone thats recently done that have a new way to install packages? seems like alot of stuff is out of date and i keep getting warnings when im using npm install for everything
Thank You Boss for the Content.
why does it not work to run the project? error "PORT" is writtten wrong or not found"
I am from India. please help me with that updated package. I am not getting it
A react dashboard has been on my plate as my next project for a minute now. Now that it's staring me in the face I may as well start.
Guys for the sidebar for onHover the icons kinda bobble; who is providing that animation can someone explain thanks !