1.0.2 • Published 5 years ago

react-use-web-share v1.0.2

Weekly downloads
1,048
License
MIT
Repository
github
Last release
5 years ago

useWebShare

A custom react hook for triggering the native web share dialog in supported browsers

Demo

Usage

npm install react-use-web-share
const { loading, isSupported, share } = useWebShare();

function onClick() {
  share();
}

See example directory for full example.

Parameters

Parameterdescriptiondefaultrequired
onSuccesscalled on successfully sharing the content() => {}false
onErrorcalled when caught error from navigator share content() => {}false

Returns

NameTypeDescription
loadingbooleanLoading state
isSupportedbooleanDetects whether the feature is supported in user's browser. Can be used to show the fallback
sharefunctioncan be called to trigger the native share popup

share

This is the function that triggers the native share dialog in browser.

This takes an object as argument.

Namedescriptiondefault
titletitle of shared itemdocument.title
texttext of shared item
urlurl to be sharedcanonical url if present, otherwise current url

Contributing

  1. Install dependencies
npm install
  1. Run dev for lib
npm run dev
  1. Run demo
npm start