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

https://github.com/agneym/usepip

A custom react hook for triggering Picture in Picture functionality
https://github.com/agneym/usepip

hooks picture-in-picture react

Last synced: 6 months ago
JSON representation

A custom react hook for triggering Picture in Picture functionality

Awesome Lists containing this project

README

          

# usePip





code style: prettier

A custom React hook to use [Picture in Picture](https://wicg.github.io/picture-in-picture/) mode in [supported browsers](https://caniuse.com/#feat=picture-in-picture).

[Demo](https://agneym.github.io/usePip/)

## Installation

```bash
npm install use-pip
```

Feel free to replace with yarn counterparts.

## Usage:

```javascript
const { loading, error, toggle } = usePip(videoRef);
```

See example directory for complete code.

### Parameters:

| Parameter | description | required? | default |
| :-------: | :-----------------------: | :-------: | :-----: |
| videoRef | Ref for the video element | true | null |

### Return:

| Name | Type | Description |
| :-----: | :---------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| loading | boolean | Manages loading time for setting for detecting support |
| error | string | Error state as described by [spec](https://wicg.github.io/picture-in-picture/). Holds value `NotSupportedError` if browser or video does not support attribute. |
| toggle | function | toggles state of PiP in document |

## Contributing

1. Install dependencies

```
npm install
```

2. Run dev for lib

```
npm run dev
```

3. Run demo

```
npm start
```