Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryohidaka/gitbeaker-hooks

React Hooks library for Gitbeaker.
https://github.com/ryohidaka/gitbeaker-hooks

git gitbeaker gitlab react react-hooks

Last synced: about 1 month ago
JSON representation

React Hooks library for Gitbeaker.

Awesome Lists containing this project

README

        

# gitbeaker-hooks

[![npm version](https://badge.fury.io/js/gitbeaker-hooks.svg)](https://badge.fury.io/js/gitbeaker-hooks)
![build](https://github.com/ryohidaka/gitbeaker-hooks/workflows/Build/badge.svg)
[![codecov](https://codecov.io/gh/ryohidaka/gitbeaker-hooks/graph/badge.svg?token=RHP9TB2F51)](https://codecov.io/gh/ryohidaka/gitbeaker-hooks)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B6TVH92)

## Overview

React Hooks library for [Gitbeaker](https://github.com/jdalrymple/gitbeaker).

## Installation

You can install this library using npm:

```shell
npm install gitbeaker-hooks
```

## Usage

Wrap your app with the `GitbeakerProvider` and provide options object with `token` property.

```tsx
import { GitbeakerProvider } from "gitbeaker-hooks";

const gitbeakerOptions = {
token: "your-access-token",
};

ReactDOM.render(




,
document.getElementById("root"),
);
```

Use the provided hooks to fetch GitLab data:

- useProjects
- useRepositoryTrees
- useBranches

```tsx
import { useProjects } from "gitbeaker-hooks";

function App() {
const { projects, isLoading } = useProjects();

if (isLoading) {
return

Loading...
;
}
return (
<>

    {projects?.map((project) =>
  • {project.name}
  • )}

>
);
}

export default App;
```

## API

### Hooks

- `useProjects(options)` - Fetch multiple projects.

- `useRepositoryTrees(projectId, options)` - Get a list of repository files and directories in a project.

- `useBranches(projectId, options)` - Get a list of repository branches from a project, sorted by name alphabetically.

### GitbeakerProvider

The `GitbeakerProvider` component should be used to wrap your app and provide the `options` object. The `options` object must include the `token` property.

## Link

- [Gitbeaker](https://github.com/jdalrymple/gitbeaker)
- [@gitbeaker/rest](https://www.npmjs.com/package/@gitbeaker/rest)
- [Docs for GitLab REST API](https://archives.docs.gitlab.com/16.4/ee/api/rest/)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.