Skip to content

useShare ​

Hook that utilizes the share api

browser
test coverage
Last changed: 9 days ago

TIP

This hook uses share 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 { useShare } from '@siberiacancode/reactuse';

Usage ​

typescript
const { share, supported } = useShare();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
params?UseShareParams-The use share options

Returns

UseShareReturn

Type declaration ​

typescript
export interface UseShareParams {
  /** Array of files to be shared */
  files?: File[];
  /** Text content to be shared */
  text?: string;
  /** Title of the content being shared */
  title?: string;
  /** URL link to be shared */
  url?: string;
}

export interface UseShareReturn {
  /** Whether the Web Share API is supported in the current environment */
  supported: boolean;
  /** Function to trigger the native share dialog */
  trigger: (shareParams: ShareData) => Promise<void>;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
B
babin
babin
H
hywax
hywax
Z
zeroqs
zeroqs

Released under the MIT License.