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

https://github.com/react-sandbox/react-use-favicon

✨ Dynamic page favicon hook
https://github.com/react-sandbox/react-use-favicon

favicons hook react react-hook typescript

Last synced: 4 months ago
JSON representation

✨ Dynamic page favicon hook

Awesome Lists containing this project

README

          

react-use-favicon


Build status
Dependencies
Build size
Package downloads


Reddit favicon
Reddit warning favicon
Reddit success favicon

✨ React hook to dynamically update your page’s favicon.

## Usage

### Install

Install the `@williamgrosset/react-use-favicon` package:

```bash
npm install @williamgrosset/react-use-favicon
```

### Import

Import the `useFavicon` hook:

```tsx
import React from 'react'
import useFavicon from '@williamgrosset/react-use-favicon'

export default function App() {
const { url, update, restore } = useFavicon()

return (


{url && Favicon}
update('/favicon.ico')}>Update
Restore

)
}
```

### API

`useFavicon` hook returns:

| Prop | Type | Default | Description |
| --------- | ----------------------- | ------- | ------------------- |
| `url` | `string` | `''` | Current favicon URL |
| `update` | `(src: string) => void` | - | Update the favicon |
| `restore` | `() => void` | - | Restore the favicon |

### Parameters

`useFavicon` hook options:

| Prop | Type | Default | Description |
| ----------- | -------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `selectors` | `string` | `"link[rel*='icon']"` | [Valid CSS selector(s)](https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors) |

## Development

### Local

```
pnpm install
pnpm build
```

### Tests

```
pnpm test
```

### Demo

Within `demo` directory:

```
pnpm install
pnpm start
```

## License

MIT