5.1.0 • Published 3 months ago

react-share v5.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

react-share

NPM npm bundle size downloads downloads

Social media share buttons and share counts for your React apps.

Share buttons screenshot

Install

npm install react-share

Features

  • no external script loading, i.e. no dependencies on SDKs
  • supports tree shaking with ES modules
  • opens a popup share-window
  • share buttons for:
    • Facebook
    • Facebook Messenger
    • X (formerly Twitter)
    • Telegram
    • Whatsapp
    • LinkedIn
    • Pinterest
    • VK
    • Odnoklassniki
    • Reddit
    • Tumblr
    • Mail.Ru
    • LiveJournal
    • Viber
    • Workplace
    • Line
    • Weibo
    • Pocket
    • Instapaper
    • Hatena
    • Gab
    • email
  • share counts for
    • Facebook
    • Pinterest
    • VK
    • Odnoklassniki
    • Reddit
    • Tumblr
    • Hatena
  • social media icons included in the library
  • supports also custom icons

Demo

React compatibility

VersionCompatible React versions
10.13.x, 0.14.x, 15.x.x.
215, 16
315, 16
3.0.1^16.3.
4^16.3, 17, 18
517, 18

API

Share buttons

import {
  EmailShareButton,
  FacebookShareButton,
  GabShareButton,
  HatenaShareButton,
  InstapaperShareButton,
  LineShareButton,
  LinkedinShareButton,
  LivejournalShareButton,
  MailruShareButton,
  OKShareButton,
  PinterestShareButton,
  PocketShareButton,
  RedditShareButton,
  TelegramShareButton,
  TumblrShareButton,
  TwitterShareButton,
  ViberShareButton,
  VKShareButton,
  WhatsappShareButton,
  WorkplaceShareButton,
} from "react-share";
Share button props
Required propsOptional props
Allchildren (string/element): React nodeurl (string): URL of the shared pagedisabled (bool): Disables click action and adds "disabled" classdisabledStyle (object, default={ opacity: 0.6 }): Disabled stylewindowWidth, windowHeight (number, different default for all share buttons): opened window dimensionsbeforeOnClick (() => Promise/() => void): Takes a function that returns a Promise to be fulfilled before calling onClick. If you do not return promise, onClick is called immediately.openShareDialogOnClick (boolean): Open dialog on click. Defaults to true except on EmailShareButtononShareWindowClose (() => void): Takes a function to be called after closing share dialog.resetButtonStyle (boolean, default=true): Reset button element style. Preferred to be set to false if you want to customize the button style.
EmailShareButton-subject (string): Title of the shared pagebody (string): Email, will be prepended to the url.separator (string, default=" "): Separates body from the url
FacebookShareButton-hashtag (string): A hashtag specified by the developer to be added to the shared content. People will still have the opportunity to remove this hashtag in the dialog. The hashtag should include the hash symbol.
FacebookMessengerShareButtonappId (string): Facebook application idredirectUri (string): The URL to redirect to after sharing (default: the shared url).to (string): A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients.
HatenaShareButton-title (string): Title of the shared page
InstapaperShareButton-title (string): Title of the shared pagedescription (string): Description of the shared page
LinkedinShareButton-title (string): Title of the shared pagesummary (string): Description of the shared pagesource (string): Source of the content (e.g. your website or application name)
LineShareButton-title (string): Title of the shared page
LivejournalShareButton-title (string): Title of the shared pagedescription (string): Description of the shared page
MailruShareButton-title (string): Title of the shared pagedescription (string): Description of the shared pageimageUrl (string): An absolute link to the image that will be shared
OKShareButton-title (string): Title of the shared pagedescription (string): Description of the shared pageimage (string): An absolute link to the image that will be shared
PinterestShareButtonmedia (string): An absolute link to the image that will be pinneddescription (string): Description for the sharedpinId (string): Id of existing pin - If you’ve already pinned this page, use this to treat any new Pins of this page as repins of the original. Doing this can give you a better feel for engagement, because any Pins you create will count towards repins of your original Pin.
PocketShareButton-title (string): Title of the shared page. Note that if Pocket detects a title tag on the page being saved, this parameter will be ignored and the title tag of the saved page will be used instead.
RedditShareButton-title (string): Title of the shared page
TelegramShareButton-title (string): Title of the shared page
TumblrShareButton-title (string): Title of the shared pagetags: (Array<string>)caption (string): Description of the shared pageposttype (string, default=link)
TwitterShareButton-title (string): Title of the shared pageurl: (string)hashtags (array): Hashtagsrelated (array): Accounts to recommend following
ViberShareButton-title (string): Title of the shared pageseparator (string), default=" ": Separates title from the url
VKShareButton-title (string): Title of the shared pageimage (string): An absolute link to the image that will be sharednoParse (boolean): If true is passed, VK will not retrieve URL informationnoVkLinks (boolean): If true is passed, there will be no links to the user's profile in the open window. Only for mobile devices
WeiboShareButton-title (string): Title of the shared pageimage (string): An absolute link to the image that will be shared
WhatsappShareButton-title (string): Title of the shared pageseparator (string, default=" "): Separates title from the url
WorkplaceShareButton-quote (string): A quote to be shared along with the link.hashtag (string): A hashtag specified by the developer to be added to the shared content. People will still have the opportunity to remove this hashtag in the dialog. The hashtag should include the hash symbol.

Share counts

import {
  FacebookShareCount,
  HatenaShareCount,
  OKShareCount,
  PinterestShareCount,
  RedditShareCount,
  TumblrShareCount,
  VKShareCount,
} from "react-share";

All share count components take in only one mandatory prop: url, which is the URL you are sharing. className prop is optional.

Example:

<FacebookShareCount url={shareUrl} />

If you want to render anything else but the count, you can provide a function as a child element that takes in shareCount as an argument and returns an element:

<FacebookShareCount url={shareUrl}>
  {(shareCount) => <span className="myShareCountWrapper">{shareCount}</span>}
</FacebookShareCount>

Icons

import {
  EmailIcon,
  FacebookIcon,
  FacebookMessengerIcon,
  GabIcon,
  HatenaIcon,
  InstapaperIcon,
  LineIcon,
  LinkedinIcon,
  LivejournalIcon,
  MailruIcon,
  OKIcon,
  PinterestIcon,
  PocketIcon,
  RedditIcon,
  TelegramIcon,
  TumblrIcon,
  TwitterIcon,
  ViberIcon,
  VKIcon,
  WeiboIcon,
  WhatsappIcon,
  WorkplaceIcon,
  XIcon,
} from "react-share";

Props:

  • size: Icon size in pixels (number)

  • round: Whether to show round or rect icons (bool)

  • borderRadius: Allow rounded corners if using rect icons (number)

  • bgStyle: customize background style, e.g. fill (object)

  • iconFillColor: customize icon fill color (string, default = 'white')

Example:

<TwitterIcon size={32} round={true} />

About semantic versioning

This library uses the standard semver convention. However, the share buttons and and counts are prone to lots of changes that are not in control of this library. For example: if Facebook decides to change or deprecate it's API in a major way, this library will not get a major version bump just because of that. Keep this in mind when you are planning the maintenance of your application.

License

MIT

Icons

Icon paths provided by: react-social-icons.

@plone/volto@contiago/toolbar@borderfreefinancial/revo-consumer@borderfreefinancial/revo-core@borderfreefinancial/revo-core-api@borderfreefinancial/revo-web-video-test@borderfreefinancial/dev-revo-consumer-lite-testing1-local@borderfreefinancial/dev-revo-consumer-lite-testing1resource-centerkuworking-coredraftkings-web-pool@hurumap/coregamestack@hurumaptest/componentsgatsby-theme-evelangatsby-theme-sanity-evelandivanru-uiplayer-reactcopado@jayellul/gatsby-theme-craftcmstoca-chat@taimoormk/react-commons-collectiontheme-gatsby-shopifyreact-easy-sharefriday.deaidexa-open-ds@elijahjpassmore/qwc2@castletech/pwa-module-eventsbrawl-capped-webpagecope-spapersonal-siteraylo-apollo@academysports/ui-component-library@everything-registry/sub-chunk-2611@herzkammer/viewsnoot-cosmeticsthemashroom-mashmyroom@front10/landing-page-book@gatsbystorefront/gatsby-theme-storefront-shopify@greyshipscode/gatsby-theme-friendly-matrix@grexie/website-common@gravis-os/ui@fox-zero/gpb-web@fox-zero/tv@fox-zero/webuseform-formbuilderv4tech-flayervaluex-react-appwebstudio-appwheelmap-react@jsweb001/blog_blue_theme_01@jsweb001/blog_blue_theme_02@jsweb001/blog_carbon_white_theme@jsweb001/blog_gray_theme_01@jsweb001/blog_gray_theme_02@jsweb001/blog_green_theme_02@jsweb001/blog_white_theme_01@jsweb001/school_green_theme_light_dashed@jsweb001/school_white_theme_light@jsweb001/school_white_theme_light_dashed@kowalevski/gatsby-midnight-themeestampa@liveart/injectables@liveart/market-web-client@livescorecom/react-componentsdugoly-blog@hpprc/gatsby-theme-blog@humblejs/share@hurumap-ui/core@novemist/gatsby-novemist-themegatsby-starter-hero-bloggatsby-starter-lammagatsby-starter-caspergatsby-theme-advancedgatsby-theme-amaranthgatsby-theme-blog-startergatsby-docs-startergatsby-plugin-gwpt-packagesgatsby-plugin-gwpt-packages-light@mortonprod/react-nav-componentgatsby-theme-kuworking-methodsgatsby-theme-inicigatsby-theme-materialgatsby-theme-dev-bloggatsby-theme-octahedroidgatsby-theme-q3@ntnhan30dh/gatsby-theme-wp-parent@octahedroid/ui@octahedroid/website-components@micromag/element-share-optionsfrontity-odblokowany-theme@micromag/viewer@namchey/linkpreviewgate-lowcode-componentgatsby-block-buildergatsby-all-pack-theme-startergatsby-theme-shopify-reduxgatsby-theme-wild-childgatsbyjs-themegaunt-frontity
5.1.0

3 months ago

5.0.4

3 months ago

5.0.0-rc.0

5 months ago

5.0.3

5 months ago

5.0.2

5 months ago

5.0.1

5 months ago

5.0.0

5 months ago

4.4.1

2 years ago

4.4.0

3 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0-rc.1

4 years ago

4.0.0-rc.0

4 years ago

4.0.0

4 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-beta.0

5 years ago

2.4.0

5 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.19.1

6 years ago

2.0.0-beta.0

6 years ago

1.19.0

6 years ago

1.18.1

6 years ago

1.18.0

6 years ago

1.17.0

6 years ago

1.16.0

7 years ago

1.15.1

7 years ago

1.15.0

7 years ago

1.14.1

7 years ago

1.14.0

7 years ago

1.13.3

7 years ago

1.13.2

7 years ago

1.13.1

7 years ago

1.13.0

7 years ago

1.12.1

7 years ago

1.12.0

7 years ago

1.11.1

7 years ago

1.11.0

7 years ago

1.10.2

7 years ago

1.10.1

7 years ago

1.10.0

8 years ago

1.9.3

8 years ago

1.9.2

8 years ago

1.9.1

8 years ago

1.9.0

8 years ago

1.8.5

8 years ago

1.8.4

8 years ago

1.8.3

8 years ago

1.8.2

8 years ago

1.8.1

8 years ago

1.8.0

8 years ago

1.7.0

8 years ago

1.6.1

8 years ago

1.6.0

8 years ago

1.6.0-alpha.1

8 years ago

1.5.0

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago