What is react-share?
The react-share npm package provides a collection of social media share buttons and share counts for React applications. It supports a wide range of social media platforms and allows for easy integration of sharing functionalities.
What are react-share's main functionalities?
Facebook Share Button
This feature allows you to create a Facebook share button with a customizable icon. The button can be used to share a specified URL on Facebook.
import { FacebookShareButton, FacebookIcon } from 'react-share';
const FacebookShare = () => (
<FacebookShareButton url={'https://example.com'}>
<FacebookIcon size={32} round={true} />
</FacebookShareButton>
);
Twitter Share Button
This feature allows you to create a Twitter share button with a customizable icon. The button can be used to share a specified URL and title on Twitter.
import { TwitterShareButton, TwitterIcon } from 'react-share';
const TwitterShare = () => (
<TwitterShareButton url={'https://example.com'} title={'Check this out!'}>
<TwitterIcon size={32} round={true} />
</TwitterShareButton>
);
LinkedIn Share Button
This feature allows you to create a LinkedIn share button with a customizable icon. The button can be used to share a specified URL on LinkedIn.
import { LinkedinShareButton, LinkedinIcon } from 'react-share';
const LinkedinShare = () => (
<LinkedinShareButton url={'https://example.com'}>
<LinkedinIcon size={32} round={true} />
</LinkedinShareButton>
);
Share Count
This feature allows you to display the share count for a specified URL on Facebook. Similar components are available for other social media platforms.
import { FacebookShareCount } from 'react-share';
const FacebookShareCountExample = () => (
<FacebookShareCount url={'https://example.com'} />
);
Other packages similar to react-share
react-social-sharing
The react-social-sharing package provides a set of social media sharing buttons for React applications. It supports fewer platforms compared to react-share but offers a simpler API and easier customization options.
react-social-icons
The react-social-icons package offers a collection of social media icons that can be used for sharing purposes. It focuses more on providing a wide range of icons rather than the sharing functionality itself, making it a good complement to other sharing packages.
react-share-buttons
The react-share-buttons package provides a set of customizable share buttons for various social media platforms. It offers similar functionalities to react-share but with a different set of customization options and styling capabilities.
react-share
Social media share buttons and share counts for React.
Migrating from v1 to v2? Read migration notes.
Features
- no external script loading, i.e. no dependencies on SDKs
- opens a popup share-window
- share buttons for:
- Facebook
- Twitter
- Telegram
- Google+
- Whatsapp
- LinkedIn
- Pinterest
- VK
- Odnoklassniki
- Reddit
- Tumblr
- Mail.Ru
- LiveJournal
- email
- share counts for
- Facebook
- Google+
- Linkedin
- Pinterest
- VK
- Odnoklassniki
- Reddit
- Tumblr
- social media icons included in the library
- supports also custom icons
Demo
View demo
To run demo: clone repo and run npm install && npm run run-demo
and open http://localhost:8080
.
Install
npm install react-share --save
Browser
ShareButtons work on all browsers.
ShareCounts works on all browsers, with the exception of Google Plus share count
working only on IE11 and newer (XHR CORS problem).
Compatibility
Version 1.x.x: compatible with React versions 0.13.x
, 0.14.x
and 15.x.x
.
Version 2.x.x: comptiblity is tested with React 15 and 16.
API
Share buttons
import {
FacebookShareButton,
GooglePlusShareButton,
LinkedinShareButton,
TwitterShareButton,
TelegramShareButton,
WhatsappShareButton,
PinterestShareButton,
VKShareButton,
OKShareButton,
RedditShareButton,
TumblrShareButton,
LivejournalShareButton,
EmailShareButton,
} from 'react-share';
Share button props
| Required props | Optional props |
---|
All | children : A React node (e.g. string or element)
url : URL of the shared page (string) | disabled : Disables click action and adds disabled class (bool)
disabledStyle : Style when button is disabled (object, default = { opacity: 0.6 })
windowWidth , windowHeight : opened window dimensions (int, different defaults for all share buttons)
beforeOnClick : Takes a function that returns a Promise to be fulfilled before calling onClick . If you do not return promise, onClick is called immediately.
onShareWindowClose : Takes a function to be called after closing share dialog.
additionalProps : An object to pass any additional properties, such as aria-* attributes. |
FacebookShareButton | - | quote : A quote to be shared along with the link. (string)
hashtag : 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. (string) |
GooglePlusShareButton | - | - |
LinkedinShareButton | - | title : Title of the shared page (string)
description : Description of the shared page (string) |
TwitterShareButton | - | title : Title of the shared page (string)
via : (string)
hashtags : (array) |
TelegramShareButton | - | title : Title of the shared page (string)
|
WhatsappShareButton | - | title : Title of the shared page (string)
separator : Separates title from the url, default: " " (string) |
PinterestShareButton | media : An absolute link to the image that will be pinned (string) | description : Description for the shared media. |
VKShareButton | - | title : Title of the shared page (string)
description : Description of the shared page (string)
image : An absolute link to the image that will be shared (string) |
OKShareButton | - | title : Title of the shared page (string)
description : Description of the shared page (string)
image : An absolute link to the image that will be shared (string) |
RedditShareButton | - | title : Title of the shared page (string) |
TumblrShareButton | - | title : Title of the shared page (string)
tags : (array)
caption : Description of the shared page (string) |
LivejournalShareButton | - | title : Title of the shared page (string)
description : Description of the shared page (string) |
MailruShareButton | - | title : Title of the shared page (string)
description : Description of the shared page (string)
image : An absolute link to the image that will be shared (string) |
EmailShareButton | - | subject : Title of the shared page (string)
body : Body of the email (string), defaults to shared url. |
Share counts
import {
FacebookShareCount,
GooglePlusShareCount,
LinkedinShareCount,
PinterestShareCount,
VKShareCount,
OKShareCount,
RedditShareCount,
TumblrShareCount,
} 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 {
FacebookIcon,
TwitterIcon,
TelegramIcon,
WhatsappIcon,
GooglePlusIcon,
LinkedinIcon,
PinterestIcon,
VKIcon,
OKIcon,
RedditIcon,
TumblrIcon,
LivejournalIcon,
MailruIcon,
EmailIcon,
} from 'react-share';
Props:
-
size
: Icon size in pixels (number)
-
round
: Whether to show round or rect icons (bool)
-
iconBgStyle
: customize background style, e.g. fill
(object)
-
logoFillColor
: customize logo's 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.