Skip to content

unwelch/react-web-share

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-web-share

React Web Share is a component that checks if Web Share API is supported in your browser. If is not the case, a fallback replacement appears as part of your website.

Requirements

Installation

npm install --save react-web-share
# or
yarn add react-web-share

Usage

The children of WebShare component is the trigger of the Web Share API or the Fallback UI to appear.

import React from 'react'
import ReactDOM from 'react-dom'
import WebShare from 'react-web-share'

const Demo = () => (
  <WebShare>
    <button onClick={console.log}>{'Share'}</button>
  </WebShare>
)

ReactDOM.render(<Demo />, document.getElementById('root'))

Props

static propTypes = {
  url: PropTypes.string,
  title: PropTypes.string,
  text: PropTypes.string,
  onShareSuccess: PropTypes.func,
  onShare: PropTypes.func,
  onShareFail: PropTypes.func,
  children: PropTypes.node,
  platforms: PropTypes.arrayOf(PropTypes.string)
}

static defaultProps = {
  url: window.location.href || '',
  title: document.title || '',
  text: '',
  onShareSuccess: noop,
  onShare: noop,
  onShareFail: noop,
  platforms: ['whatsapp', 'telegram', 'facebook', 'email', 'sms']
}

Highly inspired in: github.com/nimiq/web-share-shim

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published