yashsehgal / use-github-react

React hook for fetching activities and information via GitHub API
https://use-github-react.vercel.app
MIT License
1 stars 4 forks source link

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

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

Return Values

getRepositories()

Returns an object with the following methods:

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