useObjectUrl
Hook that creates and revokes an object URL for a Blob or MediaSource
browser
low
test coverage
Last changed: 1 hour ago
TIP
This hook uses URL.createObjectURL browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api
Installation
Library
CLI
Manual
typescript
import { useObjectUrl } from '@siberiacancode/reactuse';Usage
typescript
const { value } = useObjectUrl(blob);Demo
Api
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| object | Blob | MediaSource | - | The object to represent as a URL |
Returns
UseObjectUrlReturn
Type declaration
typescript
export interface UseObjectUrlReturn {
/** Current object URL */
value?: string;
/** Revokes the object URL */
revoke: () => void;
/** Creates the object URL */
set: (object: Blob | MediaSource) => void;
}Source
Source • DemoContributors
D