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

https://github.com/cergo123/react-protected-src

Use headers values when loading images in `src` attributes
https://github.com/cergo123/react-protected-src

Last synced: 5 months ago
JSON representation

Use headers values when loading images in `src` attributes

Awesome Lists containing this project

README

        

# react-protected-src

Use custom headers in `` `src` attribute easily.

With this hook you can use custom headers (e.g. JWT token) directly in `src` without worrying about the extra steps, and then you get your clean code.


#### 1. Installation:

```shell
npm i react-protected-src
```
or with yarn:
```shell
yarn add react-protected-src
```


#### 2. Import:

```javascript
import {useProtectedSrc} from "react-protected-src";
```


#### 3. Usage:

```javascript
export function Page() {
const base64 = useProtectedSrc('http://example.com/image.jpg', {'Authorization': 'Bearer SOME_TOKEN'})
return (




)
}
```


#### nextJS example:

```javascript
export default function Home() {
const base64 = useProtectedSrc('http://example.com/image.jpg', {'Authorization': 'Bearer SOME_TOKEN'})
return (




)
}
```