New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

use-github-react

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-github-react

React hook for fetching activities and information via GitHub API

  • 1.2.3-dev
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

useGitHub Hook

useGitHub is a custom React hook that provides an easy way to fetch and manage GitHub user data and repositories in your React applications.

Features

  • Fetch GitHub user information
  • Retrieve user's repositories
  • Get user's pinned repositories
  • Filter repositories by programming language
  • Get top N repositories

Installation

npm install use-github-react axios

Usage

import { useGitHub } from 'use-github-react/dist/use-github';

const MyComponent = () => {
  const { userInfo, metadata, getRepositories } = useGitHub({
    username: 'your-github-username',
    personalAccessToken: 'your-github-personal-access-token',
  });

  // Use the hook's returned data and functions
  // ...
};

API

Hook Parameters

  • username: GitHub username
  • personalAccessToken: GitHub personal access token (required for fetching pinned repositories)

Return Values

  • userInfo: Object containing user information
  • metadata: Object containing API response metadata
  • getRepositories: Function to access and filter repositories
getRepositories()

Returns an object with the following methods:

  • all(): Returns all repositories
  • withLanguage(languages): Filters repositories by programming language(s)
  • top(n): Returns top N repositories
  • pinned(): Returns pinned repositories

Example

import { useGitHub } from 'use-github-react/dist/use-github';

const MyGitHubComponent = () => {
  const { userInfo, getRepositories } = useGitHub({
    username: 'octocat',
    personalAccessToken: 'your-token-here',
  });

  console.log(userInfo);
  console.log(getRepositories().all());
  console.log(getRepositories().withLanguage(['javascript', 'typescript']));
  console.log(getRepositories().top(5));
  console.log(getRepositories().pinned());

  // Render your component using the data...
};

Note

This hook requires the axios library. Make sure to install both use-github-react and axios before using the hook.

License

MIT License

Keywords

FAQs

Package last updated on 24 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc