Skip to content

useShare

Category
Export Size
309 B
Last Changed
5 days ago

Reactive Web Share API

The share method has to be called following a user gesture like a button click. It can't simply be called on page load for example. That's in place to help prevent abuse.

Demo

Usage

tsx
import { 
useShare
} from '@reause/core'
const {
share
,
isSupported
} =
useShare
()
function
startShare
() {
share
({
title
: 'Hello',
text
: 'Hello my friend!',
url
:
location
.
href
,
}) }

Type Declarations

ts
export interface UseShareOptions {
    title?: string;
    files?: File[];
    text?: string;
    url?: string;
}

export interface UseShareReturn {
    isSupported: boolean;
    share: (overrideOptions?: UseShareOptions) => Promise<void>;
}

interface UseShareNavigatorOptions {
    navigator?: Navigator;
}

export function useShare(shareOptions?: UseShareOptions, options?: UseShareNavigatorOptions): UseShareReturn

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
ee313 - fix(core): resolve useShare audit findings (#639)
8fddc - chore!: remove all Vue-only Maybe* types and getter unions, adopt React Ref (#462)

Released under the MIT License. v0.1.8