npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

use-react-gfg

v1.0.7

Published

A React hook to fetch and display complete profile details from Geeks for Geeks. Easily integrate GFG data into your React applications with use-react-gfg.

Downloads

16

Readme

use-react-GFG

use-react-gfg is a lightweight and customizable React hook that fetches and displays a complete profile of any Geeks for Geeks user. This hook makes it easy to integrate GFG profile data into your React applications, offering a straightforward way to access and display coding statistics and achievements

NPM JavaScript Style Guide Downloads MIT License

Features

  • Full Profile Data Fetching: Retrieve detailed profile information including user stats, coding score, solved problem counts, and more.

  • Customizable UI: The hook allows easy integration into your existing React components with full control over the display of profile data.

  • Error Handling: Built-in error handling to manage issues with fetching data from the GFG API.

  • Lightweight: Minimal dependencies ensure quick and easy installation with minimal impact on your app’s performance

Detailed Blog Posts

Installation

  • npm
npm install use-react-gfg
  • yarn
yarn add use-react-gfg

Usage

Here's a simple example of how to use the useGFG hook:

import React, { useEffect } from "react";
import {useGFG} from "use-react-gfg";

function ProfileInterface() {
  const { profile, loading, error } = useGFG("bamacharan");

  useEffect(() => {
    console.log("Profile Data:", profile);
  }, [profile]);

  if (loading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>{error}</div>;
  }

  if (!profile || !profile.info) {
    return <div>Error: Profile data not found.</div>;
  }

  const { info, solvedStats } = profile;

  return (
    <div className="profile">
      <div className="basic-info">
        <h1>{info.userName}'s Profile</h1>
        {info.profilePicture && (
          <img src={info.profilePicture} alt="Profile Picture" />
        )}
        <p>Institute Rank: {info.instituteRank}</p>
        <p>Current Streak: {info.currentStreak}</p>
        <p>Max Streak: {info.maxStreak}</p>
        <p>Languages Used: {info.languagesUsed}</p>
      </div>

      <div className="solved-stats">
        <h2>Solved Stats</h2>
        <ul>
          {Object.entries(solvedStats).map(([difficulty, stats]) => (
            <li key={difficulty}>
              <h3>{difficulty}</h3>
              <p>Count: {stats.count}</p>
              {/* You can render individual questions here if needed */}
            </li>
          ))}
        </ul>
      </div>
    </div>
  );
}

export default ProfileInterface;

API

Hook: useGFG

const { profile, loading, error } = useGFG(username: string);

Parameters:

  • username (string): The GeeksforGeeks username to fetch profile data for.

Returns:

  • profile (object): The user's profile data (see Profile Interface below).
  • loading (boolean): Indicates if the data is being fetched.
  • error (string | null): Contains an error message if the fetch fails, otherwise null.

Profile interface


interface Profile {
  info: {
    userName: string;
    profilePicture: string;
    instituteRank: string;
    currentStreak: string;
    maxStreak: string;
    institution: string;
    languagesUsed: string;
    codingScore: string;
    totalProblemsSolved: string;
    monthlyCodingScore: string;
    articlesPublished: string;
  };
  solvedStats: {
    [key: string]: {
      count: number;
      questions: Array<{
        question: string;
        questionUrl: string;
      }>;
    };
  };
}

Contributions

Contributions are welcome! If you have suggestions or encounter any issues, please feel free to open an issue or submit a pull request.

Authors

License

MIT © Bama