DeveloperBreeze

Creating a Personal Dashboard with React and APIs: Keep Your Dev Life Organized

Introduction

As developers, we juggle multiple tools, projects, and tasks daily. A personal dashboard can be a game-changer, providing a centralized location to monitor your projects, check deadlines, track progress, and even integrate data from various services like GitHub, Trello, or weather updates. In this tutorial, we'll build a personal dashboard using React, with data dynamically fetched from APIs. This dashboard will help you stay organized and on top of your dev life.

1. Setting Up Your React Project

Step 1: Create a New React App

First, you'll need to set up a new React project. You can do this using the create-react-app tool:

npx create-react-app personal-dashboard
cd personal-dashboard

This command creates a new directory named personal-dashboard with a boilerplate React application.

Step 2: Install Necessary Dependencies

To fetch and manage data from APIs, we'll install a few essential packages:

npm install axios
  • axios: A promise-based HTTP client for making API requests.

Optionally, you can also install a CSS framework like Bootstrap or Material-UI for styling:

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

2. Structuring Your Dashboard

Step 1: Planning the Layout

Your personal dashboard will consist of several widgets, each displaying different information. These might include:

  • GitHub Repositories: A list of your recent GitHub repositories.
  • To-Do List: A simple to-do list to track your daily tasks.
  • Weather Widget: Current weather conditions based on your location.
  • Project Deadlines: Upcoming project deadlines or milestones.

Let’s start by setting up the main layout.

Step 2: Create the Layout Component

In the src directory, create a new file named Dashboard.js:

import React from 'react';
import './Dashboard.css';

const Dashboard = () => {
  return (
    <div className="dashboard">
      <div className="widget">
        <h3>GitHub Repositories</h3>
        {/* GitHub component will go here */}
      </div>
      <div className="widget">
        <h3>To-Do List</h3>
        {/* To-Do component will go here */}
      </div>
      <div className="widget">
        <h3>Weather</h3>
        {/* Weather component will go here */}
      </div>
      <div className="widget">
        <h3>Project Deadlines</h3>
        {/* Deadlines component will go here */}
      </div>
    </div>
  );
};

export default Dashboard;

Create a Dashboard.css file for basic styling:

.dashboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 20px;
}

.widget {
  background-color: #f4f4f4;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

Step 3: Integrate the Dashboard Component

Update src/App.js to include the dashboard component:

import React from 'react';
import Dashboard from './Dashboard';

function App() {
  return (
    <div className="App">
      <Dashboard />
    </div>
  );
}

export default App;

3. Fetching Data from APIs

Step 1: Fetching GitHub Repositories

Let’s start by fetching a list of your recent GitHub repositories. Create a new file GitHub.js in the src directory:

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const GitHub = () => {
  const [repos, setRepos] = useState([]);

  useEffect(() => {
    const fetchRepos = async () => {
      try {
        const response = await axios.get('https://api.github.com/users/YOUR_USERNAME/repos');
        setRepos(response.data);
      } catch (error) {
        console.error("Error fetching the repositories:", error);
      }
    };

    fetchRepos();
  }, []);

  return (
    <div>
      <ul>
        {repos.slice(0, 5).map((repo) => (
          <li key={repo.id}>
            <a href={repo.html_url} target="_blank" rel="noopener noreferrer">
              {repo.name}
            </a>
          </li>
        ))}
      </ul>
    </div>
  );
};

export default GitHub;

Replace YOUR_USERNAME with your actual GitHub username. This component fetches the latest repositories and displays the top five.

Integrate this component into the Dashboard.js:

import GitHub from './GitHub';

...

<div className="widget">
  <h3>GitHub Repositories</h3>
  <GitHub />
</div>

Step 2: Creating a Simple To-Do List

Create a TodoList.js file for managing tasks:

import React, { useState } from 'react';

const TodoList = () => {
  const [tasks, setTasks] = useState([]);
  const [newTask, setNewTask] = useState('');

  const addTask = () => {
    if (newTask.trim()) {
      setTasks([...tasks, newTask]);
      setNewTask('');
    }
  };

  return (
    <div>
      <input
        type="text"
        value={newTask}
        onChange={(e) => setNewTask(e.target.value)}
        placeholder="Enter a task"
      />
      <button onClick={addTask}>Add Task</button>
      <ul>
        {tasks.map((task, index) => (
          <li key={index}>{task}</li>
        ))}
      </ul>
    </div>
  );
};

export default TodoList;

Add this component to your dashboard:

import TodoList from './TodoList';

...

<div className="widget">
  <h3>To-Do List</h3>
  <TodoList />
</div>

Step 3: Adding a Weather Widget

To display the weather, create a Weather.js file:

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const Weather = () => {
  const [weather, setWeather] = useState(null);

  useEffect(() => {
    const fetchWeather = async () => {
      try {
        const response = await axios.get(`https://api.openweathermap.org/data/2.5/weather?q=YOUR_CITY&appid=YOUR_API_KEY&units=metric`);
        setWeather(response.data);
      } catch (error) {
        console.error("Error fetching the weather data:", error);
      }
    };

    fetchWeather();
  }, []);

  return (
    <div>
      {weather ? (
        <div>
          <h4>{weather.name}</h4>
          <p>{weather.weather[0].description}</p>
          <p>{weather.main.temp}°C</p>
        </div>
      ) : (
        <p>Loading weather...</p>
      )}
    </div>
  );
};

export default Weather;

Replace YOUR_CITY and YOUR_API_KEY with your actual city and OpenWeatherMap API key. Add this widget to the dashboard:

import Weather from './Weather';

...

<div className="widget">
  <h3>Weather</h3>
  <Weather />
</div>

Step 4: Displaying Project Deadlines

For managing project deadlines, create a Deadlines.js file:

import React, { useState } from 'react';

const Deadlines = () => {
  const [deadlines, setDeadlines] = useState([
    { project: 'Project A', dueDate: '2023-12-01' },
    { project: 'Project B', dueDate: '2023-12-15' }
  ]);

  return (
    <div>
      <ul>
        {deadlines.map((deadline, index) => (
          <li key={index}>
            <strong>{deadline.project}</strong>: {deadline.dueDate}
          </li>
        ))}
      </ul>
    </div>
  );
};

export default Deadlines;

Add this component to your dashboard:

import Deadlines from './Deadlines';

...

<div className="widget">
  <h3>Project Deadlines</h3>
  <Deadlines />
</div>

4. Customizing and Expanding the Dashboard

Step 1: Styling Your Dashboard

You can further enhance your dashboard’s appearance by adding custom CSS or using a CSS framework like Bootstrap or Material-UI.

Example with Material-UI:

import { Button, TextField } from '@mui/material';

...

<TextField
  label="Enter a task"
  variant="outlined"
  value={newTask}
  onChange={(e) => setNewTask(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addTask}>
  Add Task
</Button>

Step 2: Adding More Widgets

Consider adding additional widgets to your dashboard, such as:

  • Calendar: Display upcoming events or meetings.
  • News Feed: Show the latest headlines from your

favorite tech sites.

  • Productivity Tracker: Track your time spent on different tasks or projects.

Step 3: Deploying Your Dashboard

Once your dashboard is complete, you can deploy it to a web server or hosting service like Netlify, Vercel, or GitHub Pages. This will allow you to access your dashboard from any device.

To deploy your React app on Netlify:

  1. Build your app:
   npm run build
  1. Deploy the build/ directory to Netlify using the drag-and-drop feature or through a connected Git repository.

5. Conclusion

By creating a personal dashboard with React, you can centralize all the information you need to stay organized and productive as a developer. This tutorial has shown you how to fetch and display data from various APIs, create interactive widgets, and style your dashboard to make it both functional and visually appealing.

Your personal dashboard can evolve with your needs—adding new features, connecting more services, and customizing it to fit your workflow perfectly. Whether you’re tracking projects, monitoring your GitHub activity, or just checking the weather, a personal dashboard is a powerful tool to keep your dev life organized.


Continue Reading

Discover more amazing content handpicked just for you

Article

Mastering Modern Web Development: Trends, Tools, and Tutorials for 2025 and Beyond

Nothing beats learning by doing. Here’s a brief outline of a project that integrates several of the trends and tools mentioned above:

  • Framework: Choose Next.js for its versatility.
  • Styling: Integrate Tailwind CSS for a responsive design.
  • Containerization: Install Docker to containerize your application for development and production.

Feb 11, 2025
Read More
Tutorial
javascript

التعامل مع JSON في JavaScript: قراءة البيانات وكتابتها

عند استلام بيانات JSON من خادم، يمكنك تحويل هذه البيانات إلى كائنات JavaScript باستخدام JSON.parse(). هذه الدالة تأخذ سلسلة JSON وتحولها إلى كائن JavaScript يمكنك التعامل معه.

const jsonString = '{"name":"أحمد","age":30,"isMarried":false,"children":["سارة","علي"]}';

const person = JSON.parse(jsonString);
console.log(person.name);  // أحمد
console.log(person.age);   // 30

Sep 26, 2024
Read More
Cheatsheet
bash

Advanced Git Techniques Cheatsheet: Rebase, Cherry-Pick, and Interactive Staging

# Cherry-pick a single commit
git cherry-pick <commit-hash>

# Cherry-pick multiple commits
git cherry-pick <commit-hash1> <commit-hash2> ...

# Cherry-pick a range of commits
git cherry-pick <commit-hash1>^..<commit-hash2>

# Continue cherry-picking after resolving conflicts
git cherry-pick --continue

# Abort a cherry-pick operation
git cherry-pick --abort
# Switch to the main branch
git checkout main

# Cherry-pick a commit from feature-branch
git cherry-pick <commit-hash>

Aug 20, 2024
Read More
Tutorial
bash

Automating Git Workflows with Bash Scripts: Save Time and Avoid Mistakes

Standardized commit messages are crucial for maintaining a clean and understandable project history. You can automate commit operations with a script:

#!/bin/bash

# Check if commit message is provided
if [ -z "$1" ]; then
  echo "Please provide a commit message."
  exit 1
fi

# Add all changes to staging
git add .

# Commit with the provided message
git commit -m "$1"

# Push the commit to the current branch on the remote repository
git push

echo "Changes committed and pushed with message: '$1'"

Aug 20, 2024
Read More
Tutorial
javascript typescript

Building a Custom VS Code Extension: Supercharge Your Workflow

In the src/extension.ts file, you'll see that a sample command has already been registered. We’ll modify it to create our own custom command:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "my-vscode-extension" is now active!');

    let disposable = vscode.commands.registerCommand('extension.showHelloWorld', () => {
        vscode.window.showInformationMessage('Hello, World!');
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {}

Aug 20, 2024
Read More
Tutorial
javascript nodejs

Crafting Beautiful CLI Tools with Node.js: Make Command-Line Interfaces Fun

const ora = require('ora');

yargs.command({
    command: 'download',
    describe: 'Simulate a file download',
    handler() {
        const spinner = ora('Downloading file...').start();

        setTimeout(() => {
            spinner.succeed('Download complete!');
        }, 3000);
    }
});

yargs.parse();

Here, the download command simulates a file download by displaying a spinner for 3 seconds before completing the task.

Aug 20, 2024
Read More
Tutorial
python

Creating a Dynamic Cheatsheet Generator with Python and Flask

<form method="GET" action="{{ url_for('search') }}" class="form-inline mb-3">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" name="q">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>

To test the application locally, use the following command:

Aug 20, 2024
Read More
Article

Top Remote Work Tools to Boost Your Productivity

Trello is a versatile project management tool that uses boards, lists, and cards to help teams organize tasks and projects visually. It’s particularly useful for agile teams and can be adapted to fit various workflows.

  • Features:
  • Drag-and-drop task management
  • Customizable boards and cards
  • Integration with Slack, Google Drive, and more
  • Automation through Butler

Aug 08, 2024
Read More
Tutorial
javascript

Building a Modern Web Application with React and Redux

   npm install redux react-redux

Now, let's set up Redux in our React application.

Aug 05, 2024
Read More
Code
javascript

JavaScript Display To-Do List

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!