Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README.md has Updated #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 50 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# 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.
# useGitHub - A Custom React Hook for GitHub Data

## Features
Easily fetch and manage GitHub user data and repositories in your React applications with `useGitHub`.

- Fetch GitHub user information
- Retrieve user's repositories
- Get user's pinned repositories
- Filter repositories by programming language
- Get top N repositories
## 🚀 Features

## Installation
- **Fetch GitHub User Information**: Access basic details about a GitHub user.
- **Retrieve Repositories**: Fetch all repositories for a user.
- **Get Pinned Repositories**: Retrieve the user's pinned repositories.
- **Filter by Language**: Filter repositories by programming language(s).
- **Top Repositories**: Fetch the top N repositories based on stars, forks, etc.

## 📦 Installation

Get started by installing the necessary dependencies:

```bash
npm install use-github-react axios
```

## Usage
## 🛠️ Usage

To use the `useGitHub` hook, simply import and configure it with your GitHub username and personal access token:

```javascript
import { useGitHub } from 'use-github-react/dist/use-github';
Expand All @@ -27,34 +32,39 @@ const MyComponent = () => {
personalAccessToken: 'your-github-personal-access-token',
});

// Use the hook's returned data and functions
// ...
// Utilize userInfo, metadata, or repositories here...
};
```

## API
## 📘 API Documentation

### Hook Parameters

- `username`: GitHub username
- `personalAccessToken`: GitHub personal access token (required for fetching pinned repositories)
| Parameter | Type | Description |
|-----------------------|--------|--------------------------------------------|
| `username` | string | The GitHub username to fetch data for. |
| `personalAccessToken` | string | Personal access token for GitHub API. (Required for pinned repositories) |

### Return Values
### Returned Values

- `userInfo`: Object containing user information
- `metadata`: Object containing API response metadata
- `getRepositories`: Function to access and filter repositories
| Value | Type | Description |
|------------------|----------|---------------------------------------------------------|
| `userInfo` | Object | Contains user information from GitHub. |
| `metadata` | Object | API response metadata. |
| `getRepositories`| Function | Function that returns repository-related methods. |

#### `getRepositories()`
#### Repository Methods

Returns an object with the following methods:
The `getRepositories()` function returns an object with several useful methods:

- `all()`: Returns all repositories
- `withLanguage(languages)`: Filters repositories by programming language(s)
- `top(n)`: Returns top N repositories
- `pinned()`: Returns pinned repositories
- **`all()`**: Retrieves all repositories.
- **`withLanguage(languages)`**: Filters repositories by the specified programming languages.
- **`top(n)`**: Fetches the top N repositories.
- **`pinned()`**: Retrieves the user's pinned repositories.

## Example
## 🔥 Example

Here’s an example of how you can use the hook in a component:

```javascript
import { useGitHub } from 'use-github-react/dist/use-github';
Expand All @@ -65,20 +75,29 @@ const MyGitHubComponent = () => {
personalAccessToken: 'your-token-here',
});

// Logging fetched data to the console for demonstration
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...
// You can use this data to render your component...
};
```

## Note
## ⚙️ Prerequisites

Make sure you've installed the following packages before using the hook:

```bash
npm install use-github-react axios
```

## 🔑 Personal Access Token

This hook requires the `axios` library. Make sure to install both `use-github-react` and `axios` before using the hook.
To fetch pinned repositories or to make authenticated requests, you’ll need a [GitHub personal access token](https://github.com/settings/tokens). Ensure you have the necessary permissions to access repository information.

## License
## 📝 License

[MIT License](https://opensource.org/licenses/MIT)
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).