28.7 kBMarkdownView Raw
1# react-share
2
3[![NPM](https://img.shields.io/npm/v/react-share.svg)](https://www.npmjs.com/package/react-share) ![npm bundle size](https://img.shields.io/bundlephobia/min/react-share) [![downloads](https://img.shields.io/npm/dm/react-share.svg?label=monthly%20downloads)](https://www.npmjs.com/package/react-share) [![downloads](https://img.shields.io/npm/dt/react-share.svg?label=total%20downloads)](https://www.npmjs.com/package/react-share)
4
5> Social media share buttons and share counts for your React apps.
6
7![Share buttons screenshot](example.png)
8
9## Install
10
11```shell
12npm install react-share
13```
14
15## Features
16
17- no external script loading, i.e. no dependencies on SDKs
18- supports tree shaking with ES modules
19- opens a popup share-window
20- share buttons for:
21 - Facebook
22 - Facebook Messenger
23 - X (formerly Twitter)
24 - Telegram
25 - Whatsapp
26 - LinkedIn
27 - Pinterest
28 - VK
29 - Odnoklassniki
30 - Reddit
31 - Tumblr
32 - Mail.Ru
33 - LiveJournal
34 - Viber
35 - Workplace
36 - Line
37 - Weibo
38 - Pocket
39 - Instapaper
40 - Hatena
41 - Gab
42 - Bluesky
43 - email
44 - Threads
45- share counts for
46 - Facebook
47 - Pinterest
48 - VK
49 - Odnoklassniki
50 - Reddit
51 - Tumblr
52 - Hatena
53- social media icons included in the library
54- supports also custom icons
55
56## Demo
57
58- [Deployed demo](https://npm-react-share-demo.netlify.app) (from [`./demo`](./demo/))
59
60- [Codesandbox example](https://codesandbox.io/p/sandbox/react-share-demo-474q4k)
61
62- Locally: clone the repository and run `npm install && npm run demo`.
63
64## React compatibility
65
66| Version | Compatible React versions |
67| ------- | ----------------------------- |
68| 1 | `0.13.x`, `0.14.x`, `15.x.x`. |
69| 2 | `15`, `16` |
70| 3 | `15`, `16` |
71| 3.0.1 | `^16.3.` |
72| 4 | `^16.3`, `17`, `18` |
73| 5 | `17`, `18`, `19` |
74
75## API
76
77### Share buttons
78
79```js
80import {
81 EmailShareButton,
82 FacebookShareButton,
83 GabShareButton,
84 HatenaShareButton,
85 InstapaperShareButton,
86 LineShareButton,
87 LinkedinShareButton,
88 LivejournalShareButton,
89 MailruShareButton,
90 OKShareButton,
91 PinterestShareButton,
92 PocketShareButton,
93 RedditShareButton,
94 TelegramShareButton,
95 ThreadsShareButton,
96 TumblrShareButton,
97 TwitterShareButton,
98 ViberShareButton,
99 VKShareButton,
100 WhatsappShareButton,
101 WorkplaceShareButton,
102} from "react-share";
103```
104
105##### Share button props
106
107| | Required props | Optional props |
108| ---------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
109| **All** | **`children`** (string/element): React node<br />**`url`** (string): URL of the shared page | **`htmlTitle`** (string): Adds accessible `title=""` attribute to button the element<br/> **`disabled`** (bool): Disables click action and adds "disabled" class<br/>**`disabledStyle`** (object, default=`{ opacity: 0.6 }`): Disabled style<br/>**`windowWidth`, `windowHeight`** (number, different default for all share buttons): opened window dimensions<br />**`beforeOnClick`** (`() => 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.<br/>**`openShareDialogOnClick`** (boolean): Open dialog on click. Defaults to `true` except on EmailShareButton<br/>**`onShareWindowClose`** (`() => void`): Takes a function to be called after closing share dialog.<br/>**`resetButtonStyle`** (boolean, default=`true`): Reset `button` element style. Preferred to be set to `false` if you want to customize the button style. |
110| EmailShareButton | - | **`subject`** (string): Title of the shared page<br/>**`body`** (string): Email, will be prepended to the url.<br/>**`separator`** (string, default=`" "`): Separates body from the url |
111| 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. |
112| FacebookMessengerShareButton | **`appId`** (string): Facebook application id | **`redirectUri`** (string): The URL to redirect to after sharing (default: the shared url).<br />**`to`** (string): A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients. |
113| HatenaShareButton | - | **`title`** (string): Title of the shared page |
114| InstapaperShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page |
115| LinkedinShareButton | - | **`title`** (string): Title of the shared page<br/>**`summary`** (string): Description of the shared page<br/>**`source`** (string): Source of the content (e.g. your website or application name) |
116| LineShareButton | - | **`title`** (string): Title of the shared page |
117| LivejournalShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page |
118| MailruShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page<br/>**`imageUrl`** (string): An absolute link to the image that will be shared |
119| OKShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page<br/>**`image`** (string): An absolute link to the image that will be shared |
120| PinterestShareButton | **`media`** (string): An absolute link to the image that will be pinned | **`description`** (string): Description for the shared<br/>**`pinId`** (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. |
121| 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. |
122| RedditShareButton | - | **`title`** (string): Title of the shared page |
123| TelegramShareButton | - | **`title`** (string): Title of the shared page<br/> |
124| ThreadsShareButton | - | **`title`** (string): Title of the shared page<br> **`url`**: (string)<br/> |
125| TumblrShareButton | - | **`title`** (string): Title of the shared page<br/>**`tags`**: (`Array<string>`)<br/>**`caption`** (string): Description of the shared page<br/>**`posttype`** (string, default=`link`) |
126| TwitterShareButton | - | **`title`** (string): Title of the shared page<br/>**`url`**: (string)<br/>**`hashtags`** (array): Hashtags<br/>**`related`** (array): Accounts to recommend following |
127| ViberShareButton | - | **`title`** (string): Title of the shared page<br/>**`separator`** (string), default=`" "`: Separates title from the url |
128| VKShareButton | - | **`title`** (string): Title of the shared page<br/>**`image`** (string): An absolute link to the image that will be shared<br/>**`noParse`** (boolean): If true is passed, VK will not retrieve URL information<br/>**`noVkLinks`** (boolean): If true is passed, there will be no links to the user's profile in the open window. Only for mobile devices |
129| WeiboShareButton | - | **`title`** (string): Title of the shared page<br/>**`image`** (string): An absolute link to the image that will be shared |
130| WhatsappShareButton | - | **`title`** (string): Title of the shared page<br/>**`separator`** (string, default=`" "`): Separates title from the url |
131| WorkplaceShareButton | - | **`quote`** (string): A quote to be shared along with the link.<br/>**`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. |
132
133### Share counts
134
135```js
136import {
137 FacebookShareCount,
138 HatenaShareCount,
139 OKShareCount,
140 PinterestShareCount,
141 RedditShareCount,
142 TumblrShareCount,
143 VKShareCount,
144} from "react-share";
145```
146
147All share count components take in only one mandatory prop: `url`, which is the
148URL you are sharing. `className` prop is optional.
149
150Example:
151
152```jsx
153<FacebookShareCount url={shareUrl} />
154```
155
156If you want to render anything else but the count,
157you can provide a function as a child element that takes in `shareCount` as an
158argument and returns an element:
159
160```jsx
161<FacebookShareCount url={shareUrl}>
162 {(shareCount) => <span className="myShareCountWrapper">{shareCount}</span>}
163</FacebookShareCount>
164```
165
166### Icons
167
168```js
169import {
170 EmailIcon,
171 FacebookIcon,
172 FacebookMessengerIcon,
173 GabIcon,
174 HatenaIcon,
175 InstapaperIcon,
176 LineIcon,
177 LinkedinIcon,
178 LivejournalIcon,
179 MailruIcon,
180 OKIcon,
181 PinterestIcon,
182 PocketIcon,
183 RedditIcon,
184 TelegramIcon,
185 ThreadsIcon,
186 TumblrIcon,
187 TwitterIcon,
188 ViberIcon,
189 VKIcon,
190 WeiboIcon,
191 WhatsappIcon,
192 WorkplaceIcon,
193 XIcon,
194 BlueskyIcon,
195} from "react-share";
196```
197
198Props:
199
200- `size`: Icon size in pixels (number)
201
202- `round`: Whether to show round or rect icons (bool)
203
204- `borderRadius`: Allow rounded corners if using rect icons (number)
205
206- `bgStyle`: customize background style, e.g. `fill` (object)
207
208- `iconFillColor`: customize icon fill color (string, default = 'white')
209
210Example:
211
212```jsx
213<TwitterIcon size={32} round={true} />
214```
215
216### About semantic versioning
217
218This 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.
219
220## License
221
222MIT
223
224## Icons
225
226Icon paths provided by:
227[react-social-icons](https://github.com/jaketrent/react-social-icons).