Dive into the dynamic world of web development with Next.js, a React framework that delivers server-side rendering and static site generation out of the box. Today, we're going to create a comprehensive dashboard using Next.js and host it on Github. Let's get started!

Before we embark on this journey, make sure you have Node.js and npm installed. Also, familiarize yourself with React and its syntax. If you haven't installed the required tools, you can do so at nodejs.org.

Setting Up Your Development Environment
We'll begin by setting up a new Next.js project and installing the necessary dependencies.

Open your terminal or command prompt, navigate to the directory where you want to create your project, and run the following command to create a new Next.js application:
npx create-next-app@latest my-dashboard-app
Installing Dependencies

Next, we need to install some useful libraries to enhance our dashboard's functionality. Change into your project directory and run:
cd my-dashboard-app
npm install axios react-chartjs-2 chart.js
We've installed axios for API calls, and react-chartjs-2 along with chart.js to create interactive charts.
Initializing GitHub Repository

Now, let's initialize a Git repository and push our code to Github. In your terminal, run:
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/my-dashboard-app.git
git push -u origin master
Replace yourusername with your actual Github username.
Building the Dashboard

Now that our project is set up, let's create a simple dashboard with a welcome message, a chart, and some data fetched from an API.
Open the pages/index.js file in your favorite code editor. Replace the existing code with the following:




















import {useEffect, useState} from 'react';
import {Bar} from 'react-chartjs-2';
import axios from 'axios';
function Home() {
const [data, setData] = useState(null);
const [chartData, setChartData] = useState(null);
useEffect(() => {
const fetchData = async () => {
const result = await axios.get('https://jsonplaceholder.typicode.com/todos');
setData(result.data);
setChartData({
labels: result.data.map(item => item.userId),
datasets: [
{
label: 'Tasks',
data: result.data.map(item => item.userId),
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}
]
});
};
fetchData();
}, []);
if (!data || !chartData) return <div>Loading...</div>;
return (
<div>
<h1>Welcome to my Dashboard</h1>
<p>Fetched data: {JSON.stringify(data[0])}</p>
<Bar
data={chartData}
width={100}
height={50}
options={{}}
/>
</div>
);
}
export default Home;
Here, we're fetching data from JSONPlaceholder, creating chart data, and displaying it using Bar component from react-chartjs-2.
Running the Application
Start the development server by running:
npm run dev
Open your browser and navigate to http://localhost:3000 to see your shiny new dashboard!
Deploying to Github Pages
Next.js apps can be exported as static sites, which we can deploy to Github Pages. Let's do that!
First, install the required dependency:
npm install next export-assets
Exporting the Application
Now, run the following command to export your application as a static site:
npm run build
export-assets.out static
Deploying to Github Pages
Create a new repository on Github called my-dashboard-app.github.io. Then, push your exported static site to this new repository:
git init
git add .
git commit -m "Export and deploy"
git remote remove origin
git remote add origin https://github.com/yourusername/my-dashboard-app.github.io.git
git push -u origin main
Within a few seconds, your dashboard should be live at https://yourusername.github.io/my-dashboard-app. Isn't that amazing?
And there you have it! You've successfully created, Git-hub-hosted, and deployed a Next.js dashboard. Happy coding, and remember to keep exploring and improving your dashboard as you learn more about web development!