react-share

Social media share buttons and share counts for React

Github星跟踪图

react-share

npm version
Download Count

Social media share buttons and share counts for React.

Migrating from v2 to v3? Read changelog.

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
    • Whatsapp
    • LinkedIn
    • Pinterest
    • VK
    • Odnoklassniki
    • Reddit
    • Tumblr
    • Mail.Ru
    • LiveJournal
    • Viber
    • Workplace
    • Line
    • Weibo
    • Pocket
    • Instapaper
    • email
  • share counts for
    • Facebook
    • 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-demos
and open http://localhost:8080.

Install

npm install react-share --save

Compatibility

Version 1.x.x: compatible with React versions 0.13.x, 0.14.x and 15.x.x.

Version 2.x.x: compatiblity is tested with React 15 and 16.

Version 3.x.x: compatiblity is tested with React 15 and 16.

Version 3.0.1: compatible with React ^16.3.

Version 4.x.x: compatible with React >=16.3.

API

Share buttons

import {
  EmailShareButton,
  FacebookShareButton,
  InstapaperShareButton,
  LineShareButton,
  LinkedinShareButton,
  LivejournalShareButton,
  MailruShareButton,
  OKShareButton,
  PinterestShareButton,
  PocketShareButton,
  RedditShareButton,
  TelegramShareButton,
  TumblrShareButton,
  TwitterShareButton,
  ViberShareButton,
  VKShareButton,
  WhatsappShareButton,
  WorkplaceShareButton,
} from "react-share";
import {
  FacebookShareCount,
  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,
  InstapaperIcon,
  LineIcon,
  LinkedinIcon,
  LivejournalIcon,
  MailruIcon,
  OKIcon,
  PinterestIcon,
  PocketIcon,
  RedditIcon,
  TelegramIcon,
  TumblrIcon,
  TwitterIcon,
  ViberIcon,
  VKIcon,
  WeiboIcon,
  WhatsappIcon,
  WorkplaceIcon,
} 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.

主要指标

概览
名称与所有者nygardk/react-share
主编程语言TypeScript
编程语言JavaScript (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2015-10-24 09:36:56
推送于2025-02-25 11:05:48
最后一次提交2025-02-25 18:05:12
发布数72
最新版本名称v5.2.2 (发布于 2025-02-25 11:05:48)
第一版名称v1.0.0 (发布于 2015-10-24 12:36:24)
用户参与
星数2.7k
关注者数16
派生数448
提交数598
已启用问题?
问题数378
打开的问题数178
拉请求数100
打开的拉请求数10
关闭的拉请求数87
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?